結果

問題 No.1369 交換門松列・竹
ユーザー MayimgMayimg
提出日時 2021-02-20 23:41:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,382 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 206,888 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 03:04:47
合計ジャッジ時間 4,671 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 7 ms
4,348 KB
testcase_16 AC 8 ms
4,348 KB
testcase_17 AC 8 ms
4,348 KB
testcase_18 AC 7 ms
4,348 KB
testcase_19 AC 7 ms
4,348 KB
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 7 ms
4,348 KB
testcase_22 AC 7 ms
4,348 KB
testcase_23 AC 7 ms
4,348 KB
testcase_24 AC 9 ms
4,348 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 6 ms
4,348 KB
testcase_29 AC 6 ms
4,348 KB
testcase_30 AC 7 ms
4,348 KB
testcase_31 AC 7 ms
4,348 KB
testcase_32 WA -
testcase_33 AC 6 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0