結果
問題 | No.1369 交換門松列・竹 |
ユーザー |
|
提出日時 | 2021-01-29 22:06:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 15 ms / 2,000 ms |
コード長 | 1,788 bytes |
コンパイル時間 | 1,509 ms |
コンパイル使用メモリ | 81,532 KB |
最終ジャッジ日時 | 2025-01-18 09:15:23 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 33 |
ソースコード
#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, bs; for (int i = 0; i + 2 < n; ++i) { if (judge(xs[i], xs[i + 1], xs[i + 2])) continue; bs.push_back(i); 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()); if (is.size() > 10) { cout << "No\n"; return; } auto around = [&](int i) { return i < 0 || n <= i + 2 || judge(xs[i], xs[i + 1], xs[i + 2]); }; for (auto i : is) { for (int d = 0; d < 3; ++d) bs.push_back(i - d); for (int j = 0; j < n; ++j) { if (i == j) continue; swap(xs[i], xs[j]); for (int d = 0; d < 3; ++d) bs.push_back(j - d); bool ok = true; for (auto b : bs) { if (!around(b)) ok = false; } if (ok) { cout << "Yes\n"; return; } swap(xs[i], xs[j]); for (int d = 0; d < 3; ++d) bs.pop_back(); } for (int d = 0; d < 3; ++d) bs.pop_back(); } cout << "No\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int q; cin >> q; while (q--) solve(); return 0; }