結果
問題 | No.1827 最長部分スーパーリッチ門松列列 |
ユーザー |
👑 |
提出日時 | 2022-01-28 22:26:23 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 74 ms / 2,000 ms |
コード長 | 752 bytes |
コンパイル時間 | 353 ms |
コンパイル使用メモリ | 30,336 KB |
実行使用メモリ | 5,760 KB |
最終ジャッジ日時 | 2024-12-30 08:14:33 |
合計ジャッジ時間 | 3,283 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 24 |
ソースコード
#include <stdio.h> void chmax(int* a, int b) { if (*a < b) *a = b; } int solve(int N, int P[]) { int i; static int P_inv[500001]; for (i = 1; i <= N; i++) P_inv[P[i]] = i; int j, ans = 1, tmp = 1; for (i = 1; i <= N; i++) { j = P_inv[i]; if (j == 1) { if (P[j] > P[j+1]) tmp--; else tmp++; } else if (j == N) { if (P[j-1] < P[j]) tmp--; else tmp++; } else { if (P[j-1] < P[j] && P[j] > P[j+1]) tmp -= 2; else if (P[j-1] > P[j] && P[j] < P[j+1]) tmp += 2; } chmax(&ans, tmp); } return ans; } int main() { int i, t, T, N, P[500001]; scanf("%d", &T); for (t = 1; t <= T; t++) { scanf("%d", &N); for (i = 1; i <= N; i++) scanf("%d", &(P[i])); printf("%d\n", solve(N, P)); } fflush(stdout); return 0; }