結果

問題 No.979 Longest Divisor Sequence
ユーザー drken1215drken1215
提出日時 2020-02-01 00:14:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,771 bytes
コンパイル時間 1,753 ms
コンパイル使用メモリ 175,132 KB
実行使用メモリ 5,776 KB
最終ジャッジ日時 2023-10-17 14:11:01
合計ジャッジ時間 4,450 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,712 KB
testcase_01 AC 3 ms
4,712 KB
testcase_02 AC 3 ms
4,712 KB
testcase_03 AC 3 ms
4,712 KB
testcase_04 WA -
testcase_05 AC 2 ms
4,712 KB
testcase_06 AC 2 ms
4,712 KB
testcase_07 AC 3 ms
4,712 KB
testcase_08 WA -
testcase_09 AC 3 ms
4,712 KB
testcase_10 AC 16 ms
4,712 KB
testcase_11 AC 17 ms
4,712 KB
testcase_12 AC 17 ms
4,712 KB
testcase_13 WA -
testcase_14 AC 1,356 ms
5,768 KB
testcase_15 AC 462 ms
4,976 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) {
        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