結果
| 問題 | No.209 Longest Mountain Subsequence |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-06 15:22:53 |
| 言語 | C++11(old_compat) (gcc 12.4.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 67 ms / 2,000 ms |
| コード長 | 864 bytes |
| 記録 | |
| コンパイル時間 | 957 ms |
| コンパイル使用メモリ | 173,592 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2026-03-08 16:06:42 |
| 合計ジャッジ時間 | 1,512 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
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);
| ~~~~~^~~~~~~~~~
main.cpp:29:35: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
29 | for(int i=0; i<n; ++i) { scanf("%d", &a[i]); }
| ~~~~~^~~~~~~~~~~~~
ソースコード
#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;
}