結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-18 14:16:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 5,000 ms |
| コード長 | 723 bytes |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 24,192 KB |
| 実行使用メモリ | 6,144 KB |
| 最終ジャッジ日時 | 2024-10-02 11:00:07 |
| 合計ジャッジ時間 | 1,385 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 15 |
コンパイルメッセージ
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);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#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);
}