結果
| 問題 |
No.209 Longest Mountain Subsequence
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-06 15:22:53 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 864 bytes |
| コンパイル時間 | 345 ms |
| コンパイル使用メモリ | 52,068 KB |
| 最終ジャッジ日時 | 2024-11-14 19:46:19 |
| 合計ジャッジ時間 | 772 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp:6:1: error: ‘vector’ does not name a type
6 | vector<int> a;
| ^~~~~~
main.cpp:7:1: error: ‘vector’ does not name a type
7 | vector<vector<int>> dp;
| ^~~~~~
main.cpp: In function ‘int nya(int, int)’:
main.cpp:10:6: error: ‘dp’ was not declared in this scope
10 | if(dp[i][j] != -1) { return dp[i][j]; }
| ^~
main.cpp:12:11: error: ‘a’ was not declared in this scope
12 | int x = a[j] - a[i];
| ^
main.cpp:21:10: error: ‘dp’ was not declared in this scope
21 | return dp[i][j] = res;
| ^~
main.cpp: In function ‘int main()’:
main.cpp:28:5: error: ‘a’ was not declared in this scope
28 | a.assign(n, 0);
| ^
main.cpp:30:5: error: ‘dp’ was not declared in this scope
30 | dp.assign(n, vector<int>(n, -1));
| ^~
main.cpp:30:18: error: ‘vector’ was not declared in this scope
30 | dp.assign(n, vector<int>(n, -1));
| ^~~~~~
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:30:25: error: expected primary-expression before ‘int’
30 | dp.assign(n, vector<int>(n, -1));
| ^~~
main.cpp:25:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | int t; scanf("%d", &t);
| ~~~~~^~~~~~~~~~
main.cpp:27:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
using namespace std;
int n;
vector<int> a;
vector<vector<int>> dp;
int nya(int i, int j) {
if(dp[i][j] != -1) { return dp[i][j]; }
int res = 2;
int x = a[j] - a[i];
for(int k=j+1; k<n; ++k) {
int y = a[k] - a[j];
if((x > 0 && y > 0 && x < y) ||
(x < 0 && y < 0 && x < y) ||
(x > 0 && y < 0)) {
res = max(res, nya(j, k) + 1);
}
}
return dp[i][j] = res;
}
int main(void) {
int t; scanf("%d", &t);
for(int cases=0; cases<t; ++cases) {
scanf("%d", &n);
a.assign(n, 0);
for(int i=0; i<n; ++i) { scanf("%d", &a[i]); }
dp.assign(n, vector<int>(n, -1));
int res = 1;
for(int i=0; i<n; ++i) {
for(int j=i+1; j<n; ++j) {
if(a[i] == a[j]) { continue; }
res = max(res, nya(i, j));
}
}
printf("%d\n", res);
}
return 0;
}