結果

問題 No.390 最長の数列
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-07-09 01:23:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 48 ms / 5,000 ms
コード長 1,028 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 68,936 KB
実行使用メモリ 7,768 KB
最終ジャッジ日時 2024-04-10 08:55:19
合計ジャッジ時間 1,804 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,440 KB
testcase_01 AC 6 ms
7,540 KB
testcase_02 AC 6 ms
7,448 KB
testcase_03 AC 5 ms
7,400 KB
testcase_04 AC 6 ms
7,476 KB
testcase_05 AC 27 ms
7,680 KB
testcase_06 AC 48 ms
7,768 KB
testcase_07 AC 6 ms
7,672 KB
testcase_08 AC 4 ms
7,468 KB
testcase_09 AC 5 ms
7,544 KB
testcase_10 AC 28 ms
7,632 KB
testcase_11 AC 29 ms
7,752 KB
testcase_12 AC 29 ms
7,576 KB
testcase_13 AC 20 ms
7,564 KB
testcase_14 AC 47 ms
7,692 KB
testcase_15 AC 5 ms
7,476 KB
testcase_16 AC 5 ms
7,432 KB
testcase_17 AC 6 ms
7,364 KB
testcase_18 AC 6 ms
7,520 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:27:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   27 |                 scanf("%d", &x[i]);
      |                 ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)

int dp[1000000];

int main(void){
	int n; cin >> n;
	rep(i, 1000000) dp[i] = 0;
	vector<int> x(n);
	rep(i, n){
		scanf("%d", &x[i]);
	}
	sort(all(x));
	rep(i, n) dp[x[i]] = 1;
	
	reps(i, 1, 1000000){
		if(dp[i] == 0) continue;
		for (int j = 2 * i; j <= 1000000; j += i){
			if(dp[j] < 1) continue;//先に1を入れることで集合を表すフラグとしても使える
			dp[j] = max(dp[j], dp[i] + 1);
		}
	}
	/*
	rep(i, 100){
		if(dp[i] != 0){
			printf("i%d dp%d\n", i, dp[i]);
		}
	}
	*/
	int ans = 0;
	rep(i, n){
		ans = max(dp[x[i]], ans);
	}
	printf("%d\n", ans);
	
	return 0;
}
0