結果

問題 No.390 最長の数列
ユーザー aRacaRac
提出日時 2016-07-18 14:16:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 5,000 ms
コード長 723 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 24,064 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 09:12:44
合計ジャッジ時間 1,174 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 5 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 25 ms
6,940 KB
testcase_06 AC 50 ms
6,948 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 31 ms
6,940 KB
testcase_11 AC 30 ms
6,940 KB
testcase_12 AC 31 ms
6,940 KB
testcase_13 AC 18 ms
6,940 KB
testcase_14 AC 41 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 4 ms
6,940 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 1000001

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