結果

問題 No.979 Longest Divisor Sequence
ユーザー simansiman
提出日時 2023-01-11 10:54:01
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,105 bytes
コンパイル時間 2,614 ms
コンパイル使用メモリ 102,864 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2023-08-23 18:29:25
合計ジャッジ時間 4,222 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,844 KB
testcase_01 AC 3 ms
5,724 KB
testcase_02 AC 3 ms
5,756 KB
testcase_03 AC 4 ms
5,788 KB
testcase_04 AC 3 ms
5,820 KB
testcase_05 AC 3 ms
5,776 KB
testcase_06 AC 3 ms
5,808 KB
testcase_07 AC 3 ms
5,756 KB
testcase_08 AC 3 ms
5,720 KB
testcase_09 AC 3 ms
5,804 KB
testcase_10 AC 5 ms
5,732 KB
testcase_11 AC 3 ms
5,868 KB
testcase_12 AC 4 ms
5,832 KB
testcase_13 AC 49 ms
6,948 KB
testcase_14 AC 111 ms
6,916 KB
testcase_15 AC 37 ms
6,176 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