結果

問題 No.1369 交換門松列・竹
ユーザー maimai
提出日時 2021-01-29 21:11:54
言語 cLay
(20240104-1)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 2,299 ms
コンパイル使用メモリ 163,404 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-19 02:06:02
合計ジャッジ時間 8,261 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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];

bool tryk(int i, int k) {
  int kmin = max(0, k-3);
  int kmax = min(N-1, k+3);
  int vmin = max(0, k-6);
  int vmax = min(N-3, k+4);
  for (int p = kmin; p <= kmax; ++p) {
    if (i == p) continue;
    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]);
    }
    swap(A[i], A[p]);
    if (ok) return true;
  }
  return false;
}

bool solve() {
  vector<int> notks;
  rd(N);
  rd(A(N));
  
  REP(i, N-2) {
    if (!kado(A[i], A[i+1], A[i+2])) {
      notks.push_back(i);
    }
  }
  
  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