結果

問題 No.390 最長の数列
ユーザー aRacaRac
提出日時 2016-07-18 12:55:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 586 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 22,400 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 15:13:37
合計ジャッジ時間 2,548 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 WA -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 WA -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void init()’:
main.cpp:9:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:10:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ 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("max is %d\n", max);
}
0