結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,976 KB
testcase_01 AC 3 ms
4,964 KB
testcase_02 AC 3 ms
4,928 KB
testcase_03 AC 3 ms
4,984 KB
testcase_04 AC 3 ms
4,928 KB
testcase_05 AC 3 ms
4,972 KB
testcase_06 AC 4 ms
4,928 KB
testcase_07 AC 3 ms
4,980 KB
testcase_08 AC 4 ms
4,908 KB
testcase_09 AC 3 ms
5,004 KB
testcase_10 AC 4 ms
4,876 KB
testcase_11 AC 4 ms
4,996 KB
testcase_12 AC 4 ms
4,916 KB
testcase_13 AC 48 ms
6,140 KB
testcase_14 WA -
testcase_15 AC 36 ms
5,296 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];

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

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

  for (int i = 0; i < N; ++i) {
    int a = A[i];
    ans = max(ans, counter[a] + 1);
    if (checked[a]) continue;
    checked[a] = true;

    int j = 2;
    while (a * j <= 300000) {
      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