結果
問題 | No.2658 L-R Nim |
ユーザー |
![]() |
提出日時 | 2024-03-01 23:21:50 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,200 ms / 7,000 ms |
コード長 | 1,877 bytes |
コンパイル時間 | 3,578 ms |
コンパイル使用メモリ | 277,228 KB |
実行使用メモリ | 51,032 KB |
最終ジャッジ日時 | 2024-09-29 15:15:15 |
合計ジャッジ時間 | 58,402 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 48 |
ソースコード
#include<bits/stdc++.h> namespace { #pragma GCC diagnostic ignored "-Wunused-function" #include<atcoder/all> #pragma GCC diagnostic warning "-Wunused-function" using namespace std; using namespace atcoder; #define rep(i,n) for(int i = 0; i < (int)(n); i++) #define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; } template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; } using ll = long long; using P = pair<int,int>; using VI = vector<int>; using VVI = vector<VI>; using VL = vector<ll>; using VVL = vector<VL>; int t1[1 << 20], t2[1 << 20]; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; VI a(n); rep(i, n) cin >> a[i]; VI s(n + 1); rep(i, n) s[i+1] = s[i] ^ a[i]; VI d; d.reserve(2 * (k + 1) * n); for (int x : a) { for (int y = x - k; y <= x + k; y++) if (y >= 0) { d.emplace_back(y ^ x); } } int left = 0, right = n; rep(i, n + 1) { if (t1[s[i]]) { right = i; break; } t1[s[i]]++; } for (int x : s) t1[x] = 0; rrep(i, n + 1) { if (t1[s[i]]) { left = i; break; } t1[s[i]]++; } for (int x : s) t1[x] = 0; sort(all(d)); d.erase(unique(all(d)), d.end()); for (int x : d) { t1[0]++; ll bad = 0; for (int i = 1; i <= n; i++) { t2[s[i]]++; bad += t1[s[i] ^ x]; } rep(i, n) { int diff = abs((x ^ a[i]) - a[i]); if (left <= i && i < right && diff <= k && bad == 0) { cout << "Yes\n"; return 0; } bad -= t1[s[i+1] ^ x]; t2[s[i+1]]--; t1[s[i+1]]++; bad += t2[s[i+1] ^ x]; } rep(i, n + 1) t1[s[i]] = 0; } cout << "No\n"; }