結果

問題 No.1369 交換門松列・竹
ユーザー simansiman
提出日時 2022-11-16 07:22:13
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,072 bytes
コンパイル時間 1,158 ms
コンパイル使用メモリ 131,976 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-17 06:52:46
合計ジャッジ時間 3,467 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 RE -
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 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 1 ms
4,348 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 16 ms
4,348 KB
testcase_16 AC 17 ms
4,348 KB
testcase_17 AC 18 ms
4,348 KB
testcase_18 AC 16 ms
4,348 KB
testcase_19 AC 15 ms
4,348 KB
testcase_20 AC 18 ms
4,348 KB
testcase_21 AC 15 ms
4,348 KB
testcase_22 AC 18 ms
4,348 KB
testcase_23 AC 16 ms
4,348 KB
testcase_24 AC 18 ms
4,348 KB
testcase_25 AC 13 ms
4,348 KB
testcase_26 WA -
testcase_27 AC 13 ms
4,348 KB
testcase_28 AC 13 ms
4,348 KB
testcase_29 AC 12 ms
4,348 KB
testcase_30 AC 17 ms
4,348 KB
testcase_31 AC 17 ms
4,348 KB
testcase_32 RE -
testcase_33 AC 10 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <cstring>
#include <vector>

using namespace std;
typedef long long ll;

bool is_kadomatsu(int a, int b, int c) {
  if (a == b) return false;
  if (a == c) return false;
  if (b == c) return false;
  if (a < b && b < c) return false;
  if (a > b && b > c) return false;

  return true;
}

void solver(int N, vector<int> A) {
  int idx = -1;
  vector<int> check_list;

  for (int i = 0; i < N - 3; ++i) {
    int a = A[i];
    int b = A[i + 1];
    int c = A[i + 2];

    if (is_kadomatsu(a, b, c)) continue;
    check_list.push_back(i);
    idx = i;
  }

  for (int i = idx; i < min(idx + 2, N); ++i) {
    for (int j = 0; j < N; ++j) {
      swap(A[i], A[j]);

      bool ok = true;
      for (int cid : check_list) {
        if (cid <= i && i <= cid + 2) {
          ok &= is_kadomatsu(A[cid], A[cid + 1], A[cid + 2]);
        } else if (cid <= j && j <= cid + 2) {
          ok &= is_kadomatsu(A[cid], A[cid + 1], A[cid + 2]);
        } else {
          ok = false;
        }
        if (not ok) break;
      }
      if (i - 2 >= 0) ok &= is_kadomatsu(A[i - 2], A[i - 1], A[i]);
      if (i - 1 >= 0 && i + 1 < N) ok &= is_kadomatsu(A[i - 1], A[i], A[i + 1]);
      if (i + 2 < N) ok &= is_kadomatsu(A[i], A[i + 1], A[i + 2]);
      if (j - 2 >= 0) ok &= is_kadomatsu(A[j], A[j + 1], A[j + 2]);
      if (j - 1 >= 0 && j + 1 < N) ok &= is_kadomatsu(A[j - 1], A[j], A[j + 1]);
      if (j + 2 < N) ok &= is_kadomatsu(A[j], A[j + 1], A[j + 2]);

      if (ok) {
        /*
        for (int v : A) {
          cerr << v << " ";
        }
        cerr << endl;
        */
        cout << "Yes" << endl;
        return;
      }

      swap(A[i], A[j]);
    }
  }

  cout << "No" << endl;
}

int main() {
  int T;
  cin >> T;

  for (int t = 0; t < T; ++t) {
    int N;
    cin >> N;
    vector<int> A(N);

    for (int i = 0; i < N; ++i) {
      cin >> A[i];
    }

    solver(N, A);
  }

  return 0;
}
0