結果

問題 No.1369 交換門松列・竹
ユーザー SSRSSSRS
提出日時 2021-01-29 22:29:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,924 bytes
コンパイル時間 1,768 ms
コンパイル使用メモリ 174,676 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 16:00:06
合計ジャッジ時間 3,199 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 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 1 ms
4,376 KB
testcase_13 AC 16 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 35 ms
4,376 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 35 ms
4,380 KB
testcase_20 AC 15 ms
4,380 KB
testcase_21 AC 35 ms
4,376 KB
testcase_22 AC 14 ms
4,380 KB
testcase_23 WA -
testcase_24 AC 15 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 8 ms
4,376 KB
testcase_29 AC 9 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;
}
struct kadomatsu{
  int N;
  vector<int> A;
  vector<bool> B;
  int sum;
  kadomatsu(vector<int> A): A(A){
    N = A.size();
    B = vector<bool>(N - 2, false);
    sum = 0;
    for (int i = 0; i < N - 2; i++){
      if (is_kadomatsu(A[i], A[i + 1], A[i + 2])){
        B[i] = true;
        sum++;
      }
    }
  }
  void update(int p, int x){
    for (int i = p - 2; i <= p; i++){
      if (0 <= i && i < N - 2){
        if (is_kadomatsu(A[i], A[i + 1], A[i + 2])){
          sum--;
        }
      }
    }
    A[p] = x;
    for (int i = p - 2; i <= p; i++){
      if (0 <= i && i < N - 2){
        if (is_kadomatsu(A[i], A[i + 1], A[i + 2])){
          sum++;
        }
      }
    }
  }
  bool check(){
    return sum == N - 2;
  }
};
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 {
      kadomatsu C(A);
      int cnt = p.size();
      bool ok = false;
      for (int j = 0; j < cnt; j++){
        for (int k = 0; k < N; k++){
          if (k != p[j]){
            C.update(k, A[p[j]]);
            C.update(p[j], A[k]);
            if (C.check()){
              ok = true;
            }
            C.update(k, A[k]);
            C.update(p[j], A[p[j]]);
          }
        }
      }
      if (ok){
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}
0