結果

問題 No.979 Longest Divisor Sequence
ユーザー simansiman
提出日時 2023-01-11 10:44:41
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,102 bytes
コンパイル時間 1,076 ms
コンパイル使用メモリ 103,164 KB
実行使用メモリ 7,288 KB
最終ジャッジ日時 2023-08-23 18:22:46
合計ジャッジ時間 2,524 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,000 KB
testcase_01 AC 3 ms
6,144 KB
testcase_02 AC 3 ms
6,196 KB
testcase_03 AC 4 ms
6,152 KB
testcase_04 AC 3 ms
6,000 KB
testcase_05 AC 4 ms
6,068 KB
testcase_06 AC 3 ms
6,104 KB
testcase_07 AC 3 ms
6,040 KB
testcase_08 AC 4 ms
6,128 KB
testcase_09 AC 3 ms
6,004 KB
testcase_10 AC 3 ms
6,132 KB
testcase_11 AC 4 ms
6,012 KB
testcase_12 AC 3 ms
6,012 KB
testcase_13 AC 49 ms
7,204 KB
testcase_14 WA -
testcase_15 AC 39 ms
6,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  int A[N];
  int A_max = 0;
  int remain_counter[300010];
  memset(remain_counter, 0, sizeof(remain_counter));

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    A_max = max(A_max, A[i]);
    remain_counter[A[i]]++;
  }

  int counter[300010];
  memset(counter, 0, sizeof(counter));
  bool checked[300010];
  memset(checked, false, sizeof(checked));
  int ans = 1;

  for (int i = 0; i <= A_max; ++i) {
    counter[i] = 1;
  }

  for (int i = 0; i < N; ++i) {
    int a = A[i];
    remain_counter[a]--;
    if (checked[a]) continue;
    checked[a] = true;

    int j = 2;
    while (a * j <= A_max) {
      int v = a * j;

      if (remain_counter[v] > 0) {
        counter[v] = max(counter[v], counter[a] + 1);
        ans = max(ans, counter[v]);
      }

      j += 1;
    }
  }

  cout << ans << endl;

  return 0;
}
0