結果

問題 No.390 最長の数列
ユーザー ferinferin
提出日時 2017-02-13 17:14:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 537 ms / 5,000 ms
コード長 1,322 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 166,280 KB
実行使用メモリ 7,760 KB
最終ジャッジ日時 2024-04-10 10:18:01
合計ジャッジ時間 4,856 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,416 KB
testcase_01 AC 3 ms
7,340 KB
testcase_02 AC 3 ms
7,344 KB
testcase_03 AC 4 ms
7,260 KB
testcase_04 AC 3 ms
7,196 KB
testcase_05 AC 537 ms
7,748 KB
testcase_06 AC 392 ms
7,604 KB
testcase_07 AC 4 ms
7,372 KB
testcase_08 AC 3 ms
7,204 KB
testcase_09 AC 3 ms
7,192 KB
testcase_10 AC 384 ms
7,760 KB
testcase_11 AC 385 ms
7,756 KB
testcase_12 AC 385 ms
7,724 KB
testcase_13 AC 260 ms
7,500 KB
testcase_14 AC 167 ms
7,628 KB
testcase_15 AC 5 ms
7,232 KB
testcase_16 AC 4 ms
7,364 KB
testcase_17 AC 21 ms
7,344 KB
testcase_18 AC 32 ms
7,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define EPS 1e-12

int x[101010], dp[1000010];

vector<int> yaku(int n) {
  vector<int> ans;
  for(int i=1; i<=sqrt(n); ++i) {
    if(!(n%i)) {
      ans.push_back(i);
      if(i*i != n) ans.push_back(n/i);
    }
  }

  return ans;
}

int main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> x[i];
  sort(x, x+n);

  memset(dp, -1, sizeof(dp));
  if(x[0] == 1) dp[1] = 1;
  else dp[1] = 0;
  REP(i, n) {
    int maxret = -INF;
    vector<int> a = yaku(x[i]);
    sort(ALL(a));
    //cout << x[i] << " j:";
    for(int j: a) {
      if(j != x[i] && dp[j] != -1) {
        //cout << j << " ";
        maxret = max(maxret, dp[j]);
      }
    }
    //cout << "max:" << maxret << endl;
    //FOR(i, 1, 10) cout << dp[i] << " "; cout << endl;
    if(maxret != -INF) dp[x[i]] = maxret+1;
  }

  int ans = -INF;
  for(int i: dp) {
    ans = max(ans, i);
  }
  //FOR(i, 1, 10) cout<<i<<" "<<dp[i]<<endl;
  cout << ans << endl;

  return 0;
}
0