結果

問題 No.1369 交換門松列・竹
ユーザー SSRSSSRS
提出日時 2021-01-29 22:31:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,158 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 168,860 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-09 16:03:13
合計ジャッジ時間 5,153 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 2 ms
4,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 RE -
testcase_20 AC 15 ms
4,384 KB
testcase_21 RE -
testcase_22 AC 14 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 14 ms
4,380 KB
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 9 ms
4,380 KB
testcase_29 AC 9 ms
4,376 KB
testcase_30 AC 15 ms
4,380 KB
testcase_31 AC 15 ms
4,380 KB
testcase_32 RE -
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;
  int sum;
  kadomatsu(vector<int> A): A(A){
    N = A.size();
    sum = 0;
    for (int i = 0; i < N - 2; i++){
      if (is_kadomatsu(A[i], A[i + 1], A[i + 2])){
        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 {
      assert(false);
      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]){
            swap(A[p[j]], A[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;
            /*
            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