結果
| 問題 |
No.390 最長の数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-06-18 14:29:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 541 bytes |
| コンパイル時間 | 350 ms |
| コンパイル使用メモリ | 52,428 KB |
| 最終ジャッジ日時 | 2024-11-14 20:04:46 |
| 合計ジャッジ時間 | 850 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:25: error: ‘pow’ was not declared in this scope
6 | constexpr int N = int(pow(10, 6)) + 10;
| ^~~
main.cpp:7:3: error: ‘vector’ was not declared in this scope
7 | vector<int> dp(N, 0); // dp[N]
| ^~~~~~
main.cpp:3:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
2 | #include <algorithm>
+++ |+#include <vector>
3 | using namespace std;
main.cpp:7:10: error: expected primary-expression before ‘int’
7 | vector<int> dp(N, 0); // dp[N]
| ^~~
main.cpp:9:10: error: expected primary-expression before ‘int’
9 | vector<int> x(n, 0); // x[n]
| ^~~
main.cpp:11:18: error: ‘x’ was not declared in this scope
11 | scanf("%d", &x[i]);
| ^
main.cpp:12:5: error: ‘dp’ was not declared in this scope
12 | dp[x[i]] = 1;
| ^~
main.cpp:14:14: error: ‘x’ was not declared in this scope
14 | sort(begin(x), end(x));
| ^
main.cpp:17:11: error: ‘dp’ was not declared in this scope
17 | if(!dp[a]) { continue; }
| ^~
main.cpp:18:7: error: ‘dp’ was not declared in this scope
18 | dp[a] = max(dp[a], dp[x[i]] + 1);
| ^~
main.cpp:21:32: error: ‘dp’ was not declared in this scope
21 | int res = *max_element(begin(dp), end(dp));
| ^~
main.cpp:8:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | int n; scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
constexpr int N = int(pow(10, 6)) + 10;
vector<int> dp(N, 0); // dp[N]
int n; scanf("%d", &n);
vector<int> x(n, 0); // x[n]
for(int i=0; i<n; ++i) {
scanf("%d", &x[i]);
dp[x[i]] = 1;
}
sort(begin(x), end(x));
for(int i=0; i<n; ++i) {
for(int a=x[i]*2; a<=N; a+=x[i]) {
if(!dp[a]) { continue; }
dp[a] = max(dp[a], dp[x[i]] + 1);
}
}
int res = *max_element(begin(dp), end(dp));
printf("%d\n", res);
return 0;
}