Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/6943ca25-5f58-8006-882b-41249eb1ca7a
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: The checker is right: the problem expects YES / NO, but the code prints First / Second. === The checker is right: the problem expects <code>YES</code> / <code>NO</code>, but the code prints <code>First</code> / <code>Second</code>. Your logic matches the sample; you just need to change the two output literals: * winning for the starting player β YES * losing for the starting player β NO Here is the corrected code (only output strings changed): <syntaxhighlight lang="cpp">#include <bits/stdc++.h> using namespace std; static inline int v2_int(int x){ int c = 0; while ((x & 1) == 0) { ++c; x >>= 1; } return c; } struct SplitMix64Hash { size_t operator()(uint64_t x) const noexcept { x += 0x9e3779b97f4a7c15ULL; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ULL; x = (x ^ (x >> 27)) * 0x94d049bb133111ebULL; return (size_t)(x ^ (x >> 31)); } }; struct Query { int n, m, idx; }; struct OddV2Solver { int m, g, half, maxN; vector<int> cold; // cold positions >0 and <= maxN vector<uint8_t> b; // b[i] = 1 if c_{i+1}-c_i = g+1, with b[0]=0 unordered_map<uint64_t, uint8_t, SplitMix64Hash> memo; OddV2Solver(int m_, int maxN_) : m(m_), g(m_ + 1), half((m_ + 1) / 2), maxN(maxN_) {} inline uint64_t key(int i, int d) const { // d <= m <= 1e6 < 2^20 return (uint64_t(i) << 20) | uint64_t(d); } bool singleton(int i, int d){ uint64_t k = key(i, d); auto it = memo.find(k); if (it != memo.end()) return it->second; bool res; if (i == 0) { // After cold position 0: only n=m is singleton (n < m are immediate-win states) res = (d == m); } else { // Previous gap g+1 creates a special mark at distance (half-1). if (b[i-1] == 1 && d == half - 1) { res = false; } // Internal mark: singleton at d/2 marks d (only possible when d even). else if ((d & 1) == 0 && singleton(i, d >> 1)) { res = false; } else { // Mark from previous cold's singleton. int t = g + int(b[i-1]) + d; if ((t & 1) == 0) { int dprev = t >> 1; if (dprev <= m && singleton(i-1, dprev)) res = false; else res = true; } else { res = true; } } } memo.emplace(k, (uint8_t)res); return res; } void build(){ cold.clear(); b.clear(); memo.clear(); int approxK = maxN / g + 8; cold.reserve(approxK); b.reserve(approxK + 1); memo.reserve((size_t)approxK * 32); b.push_back(0); // b[0] corresponds to c0->c1, and c1 = g int c = g; int i = 1; // c_i index (c0=0, c1=g) while (c <= maxN) { cold.push_back(c); bool bi = singleton(i, half); // is midpoint singleton? b.push_back((uint8_t)(bi ? 1 : 0)); c += g + (bi ? 1 : 0); ++i; } } bool isCold(int n) const { return binary_search(cold.begin(), cold.end(), n); } }; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; vector<Query> qs(t); for (int i = 0; i < t; i++) { int n, m; cin >> n >> m; qs[i] = {n, m, i}; } sort(qs.begin(), qs.end(), [](const Query& a, const Query& b){ return a.m < b.m; }); vector<string> ans(t); int L = 0; while (L < t) { int R = L; int m = qs[L].m; int maxN = 0; while (R < t && qs[R].m == m) { maxN = max(maxN, qs[R].n); ++R; } // Trivial: if n <= m, first can finish immediately. if (maxN <= m) { for (int i = L; i < R; i++) ans[qs[i].idx] = "YES"; L = R; continue; } int g = m + 1; int e = v2_int(g); // Easy case: v2(g) even => cold positions are multiples of g if ((e & 1) == 0) { for (int i = L; i < R; i++) { ans[qs[i].idx] = (qs[i].n % g == 0 ? "NO" : "YES"); } L = R; continue; } // Hard case: v2(g) odd OddV2Solver solver(m, maxN); solver.build(); for (int i = L; i < R; i++) { ans[qs[i].idx] = (solver.isCold(qs[i].n) ? "NO" : "YES"); } L = R; } for (int i = 0; i < t; i++) { cout << ans[i] << '\n'; } return 0; } </syntaxhighlight> This will match the sample format exactly (YES/NO).
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)