結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-18 14:04:26 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 722 bytes |
| コンパイル時間 | 208 ms |
| コンパイル使用メモリ | 23,936 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-15 15:34:07 |
| 合計ジャッジ時間 | 2,382 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 3 WA * 1 RE * 11 |
コンパイルメッセージ
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 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);
}