結果

問題 No.390 最長の数列
ユーザー togari_takamoto
提出日時 2016-07-09 01:17:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 57 ms / 5,000 ms
コード長 1,128 bytes
コンパイル時間 1,509 ms
コンパイル使用メモリ 165,868 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-10-02 10:39:01
合計ジャッジ時間 2,531 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

int main() {
#ifdef _WIN32
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0); // cinとcoutの連携を切る
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	ll n; cin >> n;
	vl x(n); REP(i, n) cin >> x[i];
	sort(ALL(x)); x.erase(unique(ALL(x)), x.end());

	vb exist(x.back() + 1, false);
	REP(i, x.size()) exist[x[i]] = true;

	vl dp(x.back() + 1);
	REP(i, x.back() + 1) if (exist[i]) dp[i] = 1;
	REP(i, x.back() + 1) if(exist[i]) for (ll j = 2; i * j < x.back() + 1; j++) if(exist[i * j]) dp[i * j] = max(dp[i * j], dp[i] + 1);

	ll ma = 0;
	REP(i, x.back() + 1) ma = max(ma, dp[i]);
	cout << ma << endl;
	return 0;
}
0