結果
| 問題 |
No.979 Longest Divisor Sequence
|
| ユーザー |
drken1215
|
| 提出日時 | 2020-02-01 00:18:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,402 ms / 2,000 ms |
| コード長 | 1,835 bytes |
| コンパイル時間 | 1,725 ms |
| コンパイル使用メモリ | 175,092 KB |
| 実行使用メモリ | 5,632 KB |
| 最終ジャッジ日時 | 2024-09-17 12:14:49 |
| 合計ジャッジ時間 | 4,395 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }
vector<long long> divisor(long long n) {
vector<long long> res;
for (long long i = 1; i * i <= n; ++i) {
if (n % i == 0) {
res.push_back(i);
long long j = n / i;
if (j != i) res.push_back(j);
}
}
sort(res.begin(), res.end());
return res;
}
const int MAX = 310000;
int main() {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; ++i) cin >> A[i];
vector<int> dp(MAX, 0);
for (auto a : A) {
if (a == 1) dp[a] = 1;
else {
const auto& div = divisor(a);
for (auto d : div) if (d < a) chmax(dp[a], dp[d] + 1);
}
}
int res = 0;
for (int i = 0; i < MAX; ++i) chmax(res, dp[i]);
cout << res << endl;
}
drken1215