結果
問題 | No.1368 サイクルの中に眠る門松列 |
ユーザー | pengin_2000 |
提出日時 | 2021-11-02 01:10:57 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 981 bytes |
コンパイル時間 | 364 ms |
コンパイル使用メモリ | 31,104 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-04-19 03:15:42 |
合計ジャッジ時間 | 1,441 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 1 ms
5,376 KB |
testcase_02 | AC | 13 ms
5,376 KB |
testcase_03 | AC | 4 ms
5,376 KB |
testcase_04 | AC | 6 ms
5,376 KB |
testcase_05 | AC | 28 ms
5,376 KB |
testcase_06 | AC | 27 ms
5,376 KB |
testcase_07 | AC | 27 ms
5,376 KB |
testcase_08 | AC | 28 ms
5,376 KB |
testcase_09 | AC | 28 ms
5,376 KB |
testcase_10 | AC | 28 ms
5,376 KB |
testcase_11 | AC | 28 ms
5,376 KB |
testcase_12 | AC | 27 ms
5,376 KB |
testcase_13 | AC | 28 ms
5,376 KB |
testcase_14 | AC | 28 ms
5,376 KB |
testcase_15 | AC | 28 ms
5,376 KB |
ソースコード
#include<stdio.h> int kadomatsu(long long int a, long long int b, long long int c) { if (a == c) return 0; if (a<b && b>c) return 1; if (a > b && b < c) return 1; return 0; } long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int f(int n, long long int a[]) { int i; long long int dp[200005]; dp[0] = 0; for (i = 0; i < n; i++) { dp[i + 1] = dp[i]; if (i >= 2) if (kadomatsu(a[i - 2], a[i - 1], a[i]) > 0) dp[i + 1] = max(dp[i + 1], dp[i - 2] + a[i - 2]); } return dp[n]; } int main() { int t; scanf("%d", &t); int n, i; long long int a[200005]; long long int ans; for (; t > 0; t--) { scanf("%d", &n); for (i = 0; i < n; i++) scanf("%lld", &a[i]); ans = f(n, a); a[n] = a[0]; for (i = 0; i < n; i++) a[i] = a[i + 1]; ans = max(ans, f(n, a)); a[n] = a[0]; for (i = 0; i < n; i++) a[i] = a[i + 1]; ans = max(ans, f(n, a)); printf("%lld\n", ans); } return 0; }