結果
問題 | No.1369 交換門松列・竹 |
ユーザー |
|
提出日時 | 2021-02-20 23:41:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,382 bytes |
コンパイル時間 | 2,965 ms |
コンパイル使用メモリ | 197,464 KB |
最終ジャッジ日時 | 2025-01-19 02:49:00 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 22 WA * 11 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;signed main() {ios::sync_with_stdio(false); cin.tie(0);auto isKadomatsu = [&] (int x, int y, int z) -> bool {if (y > x) {return y > z;}if (y < x) {return y < z;}return false;};auto isKadomatsuArray = [&] (const vector<int>& v) -> bool{for (int i = 1; i + 1 < (int) v.size(); i++) {if (!isKadomatsu(v[i - 1], v[i], v[i + 1])) return false;}return true;};auto solve = [&] () -> string {int n;cin >> n;vector<int> a(n);for (auto& x : a) cin >> x;int center1 = -1;for (int i = 1; i < n - 1; i++) {if (!isKadomatsu(a[i - 1], a[i], a[i + 1])) center1 = i;}int center2 = -1;for (int i = 1; i < n - 1; i++) {if (abs(i - center1) > 2 && !isKadomatsu(a[i - 1], a[i], a[i + 1])) center2 = i;}vector<int> candi;if (center1 >= 1) {for (int i = center1 - 1; i <= center1 + 1; i++) candi.emplace_back(i);}if (center2 >= 1) {for (int i = center2 - 1; i <= center2 + 1; i++) candi.emplace_back(i);}for (auto& x : candi) for (auto& y : candi) {vector<int> v = a;swap(v[x], v[y]);if (isKadomatsuArray(v)) return "Yes";}return "No";};int t;cin >> t;while (t--) cout << solve() << '\n';return 0;}