結果
問題 | No.2343 (l+r)/2 |
ユーザー |
|
提出日時 | 2023-06-09 21:48:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 245 ms / 2,000 ms |
コード長 | 2,367 bytes |
コンパイル時間 | 1,765 ms |
コンパイル使用メモリ | 197,064 KB |
最終ジャッジ日時 | 2025-02-13 23:52:49 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 14 |
ソースコード
#ifndef hari64 #include <bits/stdc++.h> // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #define debug(...) #else #include "util/viewer.hpp" #define debug(...) viewer::_debug(__LINE__, #__VA_ARGS__, __VA_ARGS__) #endif using namespace std; constexpr int INF = 1001001001; constexpr long long INFll = 1001001001001001001; template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } bool solve(int N, vector<double>& As) { if (N == 1) { return abs(As[0] - 0.5) < 1e-8; } for (int i = 0; i < N - 1; i++) { vector<double> Bs = As; Bs[i] += Bs[i + 1]; Bs[i] /= 2; Bs.erase(Bs.begin() + i + 1); if (solve(N - 1, Bs)) { // debug(N - 1, Bs); return true; } } return false; } bool fast(int N, vector<int>& As) { if (As[0] != As[N - 1]) { return true; } if (As[0] == 1) { for (int i = 0; i < N; i++) { As[i] = 1 - As[i]; } } int cnt = 0; for (int i = 0; i < N - 1; i++) { if (As[i] == 1 && As[i + 1] == 1) { return true; } if (As[i] != As[i + 1]) { cnt++; } } if (cnt >= 8) { return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); // for (int N = 1; N < 15; N++) { // for (int bit = 0; bit < (1 << N); bit++) { // vector<double> As(N); // for (int i = 0; i < N; i++) { // As[i] = (bit >> i) & 1; // } // vector<int> _As(N); // for (int i = 0; i < N; i++) { // _As[i] = As[i]; // } // bool solve_b = solve(N, As); // if (!solve_b) { // debug(N, _As); // } // if (solve_b != fast(N, _As)) { // debug(N, _As); // // assert(false); // } // } // } int T; cin >> T; while (T--) { int N; cin >> N; vector<int> As(N); for (int i = 0; i < N; i++) { cin >> As[i]; } cout << (fast(N, As) ? "Yes" : "No") << endl; } return 0; }