結果

問題 No.1369 交換門松列・竹
ユーザー SSRSSSRS
提出日時 2021-01-29 22:10:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,232 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 169,296 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 15:35:13
合計ジャッジ時間 3,217 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
bool is_kadomatsu(int a, int b, int c){
  return (b < a && b < c || b > a && b > c) && a != c;
}
int main(){
  int T;
  cin >> T;
  for (int i = 0; i < T; i++){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int j = 0; j < N; j++){
      cin >> A[j];
    }
    vector<int> B(N, 0);
    for (int j = 0; j < N - 2; j++){
      if (!is_kadomatsu(A[j], A[j + 1], A[j + 2])){
        B[j]++;
        B[j + 1]++;
        B[j + 2]++;
      }
    }
    vector<int> p;
    for (int j = 0; j < N; j++){
      if (B[j] > 0){
        p.push_back(j);
      }
    }
    if (p.size() > 6){
      cout << "No" << endl;
    } else {
      bool ok = false;
      int cnt = p.size();
      for (int j = 0; j < cnt; j++){
        for (int k = j + 1; k < cnt; k++){
          swap(A[p[j]], A[p[k]]);
          bool ok2 = true;
          for (int l = 0; l < N - 2; l++){
            if (!is_kadomatsu(A[l], A[l + 1], A[l + 2])){
              ok2 = false;
            }
          }
          if (ok2){
            ok = true;
          }
          swap(A[p[j]], A[p[k]]);
        }
      }
      if (ok){
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}
0