結果

問題 No.390 最長の数列
ユーザー aRac
提出日時 2016-07-18 12:58:18
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 579 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 20,352 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-15 15:33:57
合計ジャッジ時間 2,050 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 3 WA * 1 RE * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘init’:
main.c:9:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     scanf("%d", &N);
      |     ^~~~~~~~~~~~~~~
main.c:10:29: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   10 |     for (int i=0; i<N; i++) scanf("%d", x + i);
      |                             ^~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#define MAX_N 100000

int N;
int d[MAX_N] = {0};
int x[MAX_N];

void init(){
    scanf("%d", &N);
    for (int i=0; i<N; i++) scanf("%d", x + i);
    for (int i=0; i<N; i++) d[x[i]] = 1;
}

int main() {
    int max = 0;

    init();

    for (int i=0; i<MAX_N; i++) {
        if (d[i] == 0) continue;
        int cnt = 1;
        for (int j=i+i; j<MAX_N; j+=i) {
            if (d[j] == 1) {
                d[j] = 0;
                i = j;
                cnt++;
            }
        }
        max = (max > cnt) ? max : cnt;
    }

    printf("%d\n", max);
}
0