結果

問題 No.390 最長の数列
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2016-07-09 00:11:44
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,158 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 68,776 KB
実行使用メモリ 14,560 KB
最終ジャッジ日時 2024-04-21 08:54:13
合計ジャッジ時間 7,448 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
7,540 KB
testcase_01 AC 5 ms
7,504 KB
testcase_02 AC 6 ms
7,464 KB
testcase_03 AC 6 ms
7,480 KB
testcase_04 AC 6 ms
7,416 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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));
	dp[x[0]] = 1;
	// rep(i, n) printf("%d\n", x[i]);
	int MX = 1;
	reps(i, 1, n){
		int now = x[i];
		for (int i = now - 1; i >= 1; --i){
			if(now % i == 0){
				dp[now] = max(dp[i] + 1, dp[now]);
				if(dp[i] == MX){
					MX = max(MX, dp[now]);

					continue;
				}
			}
		}
		
		/*
		for (int i = 1; i < now; ++i){
			if(now % i == 0)
				dp[now] = max(dp[i] + 1, dp[now]);
		}
		*/
	}
	/*
	rep(i, 100000){
		if(dp[i] != 0){
			printf("dp %d i %d\n", dp[i], i);
		}
	}
	*/
	int ans = 0;
	rep(i, 1000000){
		ans = max(dp[i], ans);
	}
	printf("%d\n", ans);
	
	return 0;
}
0