結果
問題 | No.2658 L-R Nim |
ユーザー | 👑 hos.lyric |
提出日時 | 2024-03-01 23:49:36 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,402 ms / 7,000 ms |
コード長 | 3,103 bytes |
コンパイル時間 | 1,470 ms |
コンパイル使用メモリ | 121,612 KB |
実行使用メモリ | 140,536 KB |
最終ジャッジ日時 | 2024-09-29 15:23:10 |
合計ジャッジ時間 | 52,939 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
11,700 KB |
testcase_01 | AC | 4 ms
7,316 KB |
testcase_02 | AC | 5 ms
11,596 KB |
testcase_03 | AC | 3 ms
7,248 KB |
testcase_04 | AC | 5 ms
11,540 KB |
testcase_05 | AC | 71 ms
17,496 KB |
testcase_06 | AC | 4 ms
7,516 KB |
testcase_07 | AC | 8 ms
12,044 KB |
testcase_08 | AC | 121 ms
19,636 KB |
testcase_09 | AC | 48 ms
13,660 KB |
testcase_10 | AC | 5 ms
7,596 KB |
testcase_11 | AC | 71 ms
14,944 KB |
testcase_12 | AC | 5 ms
7,516 KB |
testcase_13 | AC | 5 ms
7,500 KB |
testcase_14 | AC | 3 ms
7,584 KB |
testcase_15 | AC | 79 ms
17,892 KB |
testcase_16 | AC | 5 ms
7,560 KB |
testcase_17 | AC | 22 ms
12,088 KB |
testcase_18 | AC | 19 ms
12,068 KB |
testcase_19 | AC | 4 ms
7,380 KB |
testcase_20 | AC | 49 ms
14,072 KB |
testcase_21 | AC | 4 ms
7,316 KB |
testcase_22 | AC | 3 ms
7,448 KB |
testcase_23 | AC | 11 ms
12,180 KB |
testcase_24 | AC | 34 ms
12,844 KB |
testcase_25 | AC | 2,281 ms
140,384 KB |
testcase_26 | AC | 1,510 ms
140,380 KB |
testcase_27 | AC | 2,228 ms
139,792 KB |
testcase_28 | AC | 2,120 ms
140,372 KB |
testcase_29 | AC | 1,883 ms
139,872 KB |
testcase_30 | AC | 1,529 ms
139,772 KB |
testcase_31 | AC | 1,410 ms
139,688 KB |
testcase_32 | AC | 2,167 ms
140,536 KB |
testcase_33 | AC | 7 ms
7,760 KB |
testcase_34 | AC | 37 ms
12,020 KB |
testcase_35 | AC | 1,030 ms
74,156 KB |
testcase_36 | AC | 80 ms
12,228 KB |
testcase_37 | AC | 917 ms
75,252 KB |
testcase_38 | AC | 2,236 ms
139,356 KB |
testcase_39 | AC | 2,212 ms
139,592 KB |
testcase_40 | AC | 2,276 ms
139,388 KB |
testcase_41 | AC | 2,291 ms
139,944 KB |
testcase_42 | AC | 2,232 ms
140,232 KB |
testcase_43 | AC | 2,255 ms
140,344 KB |
testcase_44 | AC | 2,291 ms
140,412 KB |
testcase_45 | AC | 2,256 ms
139,208 KB |
testcase_46 | AC | 2,248 ms
140,380 KB |
testcase_47 | AC | 2,402 ms
139,876 KB |
testcase_48 | AC | 44 ms
12,088 KB |
testcase_49 | AC | 2,016 ms
139,160 KB |
testcase_50 | AC | 2,008 ms
139,476 KB |
testcase_51 | AC | 2,232 ms
140,480 KB |
testcase_52 | AC | 2,228 ms
139,528 KB |
ソースコード
#include <cassert> #include <cmath> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <functional> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using Int = long long; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") constexpr int E = 20; int N, K; vector<int> A; bool solve() { vector<int> ASum(N + 1, 0); for (int i = 0; i < N; ++i) { ASum[i + 1] = ASum[i] ^ A[i]; } int l = 0, r = N; vector<int> app(1 << E, -1); for (int j = 0; j <= N; ++j) { int &i = app[ASum[j]]; if (~i) { chmax(l, i); chmin(r, j); } i = j; } cerr<<"l = "<<l<<", r = "<<r<<endl; if (l >= r) { return false; } vector<pair<int, int>> ps; for (int i = l; i < r; ++i) { for (int k = 0; k <= K; ++k) { ps.emplace_back(A[i] ^ (A[i] + k), i); } for (int k = 0; k <= min(K, A[i] - 1); ++k) { ps.emplace_back(A[i] ^ (A[i] - k), i); } } sort(ps.begin(), ps.end()); const int psLen = ps.size(); vector<int> freq(1 << E, 0); for (int i = 0; i <= l; ++i) { ++freq[ASum[i]]; } vector<int> can(N, 0); for (int k0 = 0, k1; k0 < psLen; k0 = k1) { for (k1 = k0; k1 < psLen && ps[k0].first == ps[k1].first; ++k1) {} const int b = ps[k0].first; for (int k = k0; k < k1; ++k) can[ps[k].second] = 1; // cerr<<"b = "<<b<<", can = "<<can<<", freq = "<<freq<<endl; int bad = 0; for (int i = l + 1; i <= N; ++i) { if (++freq[ASum[i] ^ b] == 2) ++bad; } for (int i = l; i < r; ++i) { if (can[i] && bad == 0) { // cerr<<"found i = "<<i<<", freq = "<<freq<<endl; return true; } if (freq[ASum[i + 1] ^ b]-- == 2) --bad; if (++freq[ASum[i + 1]] == 2) ++bad; } for (int i = l + 1; i <= r; ++i) --freq[ASum[i]]; for (int i = r + 1; i <= N; ++i) --freq[ASum[i] ^ b]; for (int k = k0; k < k1; ++k) can[ps[k].second] = 0; } return false; } int main() { for (; ~scanf("%d%d", &N, &K); ) { A.resize(N); for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); } const bool ans = solve(); puts(ans ? "Yes" : "No"); } return 0; }