結果

問題 No.979 Longest Divisor Sequence
ユーザー drken1215drken1215
提出日時 2020-02-01 00:18:46
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,409 ms / 2,000 ms
コード長 1,835 bytes
コンパイル時間 2,886 ms
コンパイル使用メモリ 175,040 KB
実行使用メモリ 5,684 KB
最終ジャッジ日時 2023-10-17 14:27:11
合計ジャッジ時間 5,475 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,628 KB
testcase_01 AC 3 ms
4,628 KB
testcase_02 AC 3 ms
4,628 KB
testcase_03 AC 3 ms
4,628 KB
testcase_04 AC 3 ms
4,628 KB
testcase_05 AC 3 ms
4,628 KB
testcase_06 AC 3 ms
4,628 KB
testcase_07 AC 3 ms
4,628 KB
testcase_08 AC 3 ms
4,628 KB
testcase_09 AC 3 ms
4,628 KB
testcase_10 AC 17 ms
4,628 KB
testcase_11 AC 17 ms
4,628 KB
testcase_12 AC 17 ms
4,628 KB
testcase_13 AC 48 ms
5,684 KB
testcase_14 AC 1,409 ms
5,684 KB
testcase_15 AC 465 ms
4,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
















0