結果
| 問題 | No.1827 最長部分スーパーリッチ門松列列 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-01-28 23:37:08 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 65 ms / 2,000 ms |
| コード長 | 1,090 bytes |
| コンパイル時間 | 999 ms |
| コンパイル使用メモリ | 74,248 KB |
| 最終ジャッジ日時 | 2025-01-27 17:28:50 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 |
ソースコード
#include <iostream>
#include <vector>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
while (t --> 0) {
int n;
std::cin >> n;
std::vector<int> p(n);
for (auto &e : p) {
std::cin >> e;
--e;
}
std::vector<int> q(n), r(n, 1);
for (int i = 0; i < n; ++i) {
q[p[i]] = i;
}
int sep_num = 0;
auto update = [&](int i, int v) {
sep_num -= i > 0 and r[i - 1] != r[i];
sep_num -= i + 1 < n and r[i + 1] != r[i];
r[i] = v;
sep_num += i > 0 and r[i - 1] != r[i];
sep_num += i + 1 < n and r[i + 1] != r[i];
};
int ans = 0;
for (int i : q) {
update(i, -1);
int len = sep_num + 1;
len -= i > 0 and r[i - 1] == 1;
len -= i + 1 < n and r[i + 1] == 1;
ans = std::max(ans, len);
update(i, 0);
}
std::cout << ans << '\n';
}
return 0;
}