結果

問題 No.390 最長の数列
ユーザー aRacaRac
提出日時 2016-07-18 14:12:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 23,936 KB
実行使用メモリ 9,368 KB
最終ジャッジ日時 2024-04-23 15:13:53
合計ジャッジ時間 1,144 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 5 ms
5,376 KB
testcase_03 AC 4 ms
5,376 KB
testcase_04 AC 5 ms
5,376 KB
testcase_05 AC 26 ms
5,376 KB
testcase_06 WA -
testcase_07 AC 3 ms
5,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 32 ms
6,144 KB
testcase_11 AC 32 ms
6,272 KB
testcase_12 WA -
testcase_13 AC 20 ms
5,888 KB
testcase_14 AC 44 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 4 ms
5,376 KB
testcase_18 AC 6 ms
5,504 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void init()’:
main.cpp:14:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
main.cpp:15:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     for (int i=0; i<N; i++) scanf("%d", x + i);
      |                             ~~~~~^~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#define MAX_N 1000000

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

int comp(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

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;
    qsort(x, N, sizeof(int), comp);
}

int main() {
    int max = 0;

    init();

    for (int i=0; i<N; i++) {
        if (d[x[i]] == 0) continue;
        for (int j=x[i]*2; j<MAX_N; j+=x[i]) {
            if (d[j] > 0) {
                d[j] = d[j] > d[x[i]] + 1 ? d[j] : d[x[i]] + 1;
            }
        }
    }

    for (int i=0; i<MAX_N; i++)
        max = max > d[i] ? max : d[i];

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