結果

問題 No.2218 Multiple LIS
コンテスト
ユーザー chro_96
提出日時 2023-02-17 21:49:50
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 127 ms / 3,000 ms
コード長 721 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 140 ms
コンパイル使用メモリ 39,236 KB
最終ジャッジ日時 2026-02-22 10:08:41
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>

int main () {
  int n = 0;
  int a[100000] = {};
  
  int res = 0;
  
  int ans = 0;
  int max[100000] = {};
  
  res = scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    res = scanf("%d", a+i);
  }
  
  for (int i = 0; i < n; i++) {
    if (max[a[i]-1] > max[0]) {
      max[a[i]-1]++;
    } else {
      max[a[i]-1] = max[0]+1;
    }
    for (int p = 2; p*p <= a[i]; p++) {
      if (a[i]%p == 0) {
        if (max[a[i]-1] <= max[p-1]) {
          max[a[i]-1] = max[p-1]+1;
        }
        if (max[a[i]-1] <= max[a[i]/p-1]) {
          max[a[i]-1] = max[a[i]/p-1]+1;
        }
      }
    }
    if (max[a[i]-1] > ans) {
      ans = max[a[i]-1];
    }
  }
  
  printf("%d\n", ans);
  return 0;
}
0