結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,964 KB
testcase_01 WA -
testcase_02 AC 3 ms
4,896 KB
testcase_03 AC 3 ms
4,936 KB
testcase_04 AC 3 ms
4,880 KB
testcase_05 AC 2 ms
4,968 KB
testcase_06 AC 2 ms
4,924 KB
testcase_07 AC 3 ms
4,932 KB
testcase_08 WA -
testcase_09 AC 3 ms
4,872 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 3 ms
4,956 KB
testcase_13 AC 46 ms
6,064 KB
testcase_14 AC 97 ms
6,152 KB
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

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;

  for (int i = 0; i < N; ++i) {
    cin >> A[i];
    A_max = max(A_max, 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];
    if (checked[a]) continue;
    checked[a] = true;

    int j = 2;
    while (a * j <= A_max) {
      int v = a * j;
      counter[v] = max(counter[v], counter[a] + 1);
      ans = max(ans, counter[v]);

      j += 1;
    }
  }

  cout << ans << endl;

  return 0;
}
0