結果

問題 No.390 最長の数列
ユーザー aim_cpoaim_cpo
提出日時 2017-06-20 20:44:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,734 bytes
コンパイル時間 904 ms
コンパイル使用メモリ 97,108 KB
実行使用メモリ 43,180 KB
最終ジャッジ日時 2024-04-10 06:27:36
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 65 ms
43,136 KB
testcase_06 AC 64 ms
43,008 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 63 ms
43,064 KB
testcase_12 WA -
testcase_13 AC 44 ms
34,560 KB
testcase_14 AC 66 ms
43,004 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cmath>
#include <time.h>
#include <tuple>
#define all(c) ((c).begin(),(c).end())
#define rall(c) ((c).rbegin(),(c).rend())
#define ll long long
#define fi first
#define se second
#define inf (999999999)
using namespace std;
const ll MOD = 1e9 + 7;
const double PI = acos(-1.0);
//---------------------------------------------------------------------------------------------//
int n;
int a[100001];
int dp[100001][100];

inline int solve2() {
	for (int i = 0; i <= n; i++)for (int j = 0; j < 100; j++)dp[i][j] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 100; j++) {
			if (dp[i][j] == 0) {
				dp[i + 1][0] = 0;
				dp[i + 1][1] = a[i];
			}
			else {
				if (a[i] % dp[i][j] == 0) {
					dp[i + 1][j + 1] = a[i];
					dp[i + 1][j] = dp[i][j];
				}
				else {
					dp[i + 1][j] = dp[i][j];
				}
			}
		}
	}
	int res = 0;
	for (int i = 0; i < 100; i++) {
		if (dp[n][i] != 0) {
			res = i;
		}
	}
	return res;
}

int solve(int nown,int lastnumber,int s) {
	if (nown == n) {
		return s;
	}
	if (lastnumber == 0) {
		int res=max(solve(nown + 1, a[nown], 1), solve(nown + 1, 0, 0));
		return res;
	}
	else {
		int res;
		if (a[nown] % lastnumber == 0) {
			res = max(solve(nown + 1, a[nown], s + 1), solve(nown + 1, lastnumber, s));
		}
		else {
			res = solve(nown + 1, lastnumber, s);
		}
		return res;
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	cout << solve2() << endl;
	return 0;
}
0