結果

問題 No.2518 Adjacent Larger
ユーザー 👑 emthrmemthrm
提出日時 2023-10-27 21:47:04
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,278 bytes
コンパイル時間 2,464 ms
コンパイル使用メモリ 250,832 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-27 21:47:08
合計ジャッジ時間 3,597 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

void solve() {
  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  if (ranges::count(a, 0) == 0 || ranges::count(a, 2) == 0) {
    cout << "No\n";
    return;
  }
  REP(i, n) {
    if (a[i] != 1 && a[i] == a[(i + 1) % n]) {
      cout << "No\n";
      return;
    }
    if (a[i] == 0 && a[(i + 2) % n] == 0 && a[(i + 1) % n] != 2) {
      cout << "No\n";
      return;
    }
    if (a[i] == 2 && a[(i + 2) % n] == 2 && a[(i + 1) % n] != 0) {
      cout << "No\n";
      return;
    }
  }
  cout << "Yes\n";
}

int main() {
  // const int n = 4;
  // vector<int> a(n);
  // iota(a.begin(), a.end(), 0);
  // set<vector<int>> st;
  // do {
  //   vector<int> b(n);
  //   REP(i, n) b[i] = (a[(i - 1 + n) % n] > a[i]) + (a[(i + 1) % n] > a[i]);
  //   st.emplace(b);
  // } while (ranges::next_permutation(a).found);
  // vector<int> c(n);
  // const auto f = [&](auto f, const int i, const bool has_0, const bool has_2) -> void {
  //   if (i == n) {
  //     if (has_0 && has_2 && (c.back() == 1 || c.front() != c.back())) {
  //       if (!st.contains(c)) {
  //         REP(i, n) cout << c[i] << " \n"[i + 1 == n];
  //         exit(0);
  //       }
  //     }
  //     return;
  //   }
  //   REP(x, 3) {
  //     c[i] = x;
  //     if (i == 0 || c[i] == 1 || c[i - 1] != c[i]) f(f, i + 1, has_0 || x == 0, has_2 || x == 2);
  //   }
  // };
  // f(f, 0, false, false);

  int t; cin >> t;
  while (t--) solve();
  return 0;
}
0