結果
| 問題 | No.1369 交換門松列・竹 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-29 21:38:26 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,305 bytes |
| 記録 | |
| コンパイル時間 | 1,353 ms |
| コンパイル使用メモリ | 80,640 KB |
| 最終ジャッジ日時 | 2025-01-18 09:01:55 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 24 WA * 9 |
ソースコード
#line 1 "main.cpp"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool judge(int a, int b, int c) {
if (a == c) return false;
return (a < b && b > c) ||
(a > b && b < c);
}
bool judge_all(const vector<int>& xs) {
int n = xs.size();
for (int i = 0; i + 2 < n; ++i) {
if (!judge(xs[i], xs[i + 1], xs[i + 2])) return false;
}
return true;
}
void solve() {
int n;
cin >> n;
vector<int> xs(n);
for (auto& x : xs) cin >> x;
vector<int> is;
for (int i = 0; i + 2 < n; ++i) {
if (judge(xs[i], xs[i + 1], xs[i + 2])) continue;
for (int j = 0; j < 3; ++j) is.push_back(i + j);
}
sort(is.begin(), is.end());
is.erase(unique(is.begin(), is.end()), is.end());
int m = is.size();
if (m > 10) {
cout << "No\n";
return;
}
for (int i = 0; i < m; ++i) {
for (int j = 0; j < i; ++j) {
swap(xs[is[i]], xs[is[j]]);
if (judge_all(xs)) {
cout << "Yes\n";
return;
}
swap(xs[is[i]], xs[is[j]]);
}
}
cout << "No\n";
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q;
cin >> q;
while (q--) solve();
return 0;
}