結果

問題 No.1369 交換門松列・竹
ユーザー maimai
提出日時 2021-01-29 21:35:35
言語 cLay
(20240104-1)
結果
AC  
実行時間 899 ms / 2,000 ms
コード長 1,382 bytes
コンパイル時間 2,409 ms
コンパイル使用メモリ 165,376 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-19 02:06:22
合計ジャッジ時間 8,981 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

bool kado(int a, int b, int c) {
  return ((a<b&&b>c)||(a>b&&b<c))&&(a!=c);
}

int N;
ll A[200010];
vector<int> notks;

bool tryk(int i, int k) {
  int kmin = max(0, k-3);
  int kmax = min(N-1, k+3);
  int vmin, vmax, wmin, wmax;
  for (int p = kmin; p <= kmax; ++p) {
    if (i == p) continue;
    vmin = max(0, p-6);
    vmax = min(N-3, p+4);
    wmin = max(0, i-6);
    wmax = min(N-3, i+4);
    swap(A[i], A[p]);
    bool ok = true;
    for (int v = vmin; v <= vmax; ++v) {
      ok &= kado(A[v], A[v+1], A[v+2]);
    }
    for (int v = wmin; v <= wmax; ++v) {
      ok &= kado(A[v], A[v+1], A[v+2]);
    }
    for (auto x : notks) {
      wmin = max(0, x-6);
      wmax = min(N-3, x+4);
      for (int v = wmin; v <= wmax; ++v) {
        ok &= kado(A[v], A[v+1], A[v+2]);
      }
    }
    swap(A[i], A[p]);
    if (ok) {
      // cout << i << ' ' << p << endl;
      // swap(A[i], A[p]);
      // wt(A(N));
      return true;
    }
  }
  return false;
}

bool solve() {
  rd(N);
  rd(A(N));
  notks.clear();
  
  REP(i, N-2) {
    if (!kado(A[i], A[i+1], A[i+2])) {
      notks.push_back(i);
    }
  }
  
  if (notks.size() > 10) {
    return false;
  }
  
  REP(i, N) {
    for (auto k : notks) {
      if (tryk(i, k)) return true;
    }
  }
  return false;
}

{
  int T;
  rd(T);
  REP(i, T) {
    if (solve()) {
      wt("Yes");
    }
    else {
      wt("No");
    }
  }
}
0