結果
| 問題 |
No.209 Longest Mountain Subsequence
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-05-20 21:21:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 629 ms / 2,000 ms |
| コード長 | 970 bytes |
| コンパイル時間 | 197 ms |
| コンパイル使用メモリ | 23,296 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-06 05:48:44 |
| 合計ジャッジ時間 | 2,282 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
12 | scanf("%d", &t);
| ~~~~~^~~~~~~~~~
main.cpp:14:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
14 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:16:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%d", &a[j]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
// TLEするかどうかテスト
#include <stdio.h>
int mt_length();
int length(int[], int, int, int);
int t, n, a[100], c[100];
int main(void) {
int i, j;
scanf("%d", &t);
for(i = 0; i < t; i++) {
scanf("%d", &n);
for(j = 0; j < n; j++) {
scanf("%d", &a[j]);
}
printf("%d\n", mt_length() );
}
return 0;
}
int mt_length() {
int i, max = 0;
for(i = 0; i < n; i++) { // めんどいので逆向きにしたやつも用意しておく
c[i] = a[n - 1 - i];
}
for(i = 0; i < n; i++) { // iを頂点とした山の長さを測る
int j = n - 1 - i, INF = 1000000001;
int l = length(a, i, 1, INF) + length(c, j, 1, INF) - 1;
max = (max < l) ? l : max;
}
return max;
}
int length(int x[], int p, int count, int diff) {
if(diff < 2) { return count; }
int i, max = count;
for(i = 0; i < p; i++) {
if(x[p] - diff < x[i] && x[i] < x[p]) {
int l = length(x, i, count + 1, x[p] - x[i]);
max = (max < l) ? l : max;
}
}
return max;
}
FF256grhy