結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 1 ms
6,944 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 WA -
testcase_15 AC 1 ms
6,940 KB
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 100000

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