QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#874271 | #9685. nim 游戏 | cooluo | 12 | 226ms | 30800kb | C++23 | 7.9kb | 2025-01-27 21:46:08 | 2025-01-27 21:46:09 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ul unsigned ll
#define LL __int128_t
#define db double
#define DB long db
#define pii pair<int, int>
#define fi first
#define se second
#define mkpr make_pair
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define rsz resize
#define eb emplace_back
#define all(c) (c).begin(), (c).end()
#define bit(k) (1 << (k))
#define Bit(k) (1ll << (k))
#define BIT(k) ((LL)1 << (k))
#define lowbit(x) ((x) & -(x))
#define bin(s, k) ((s) >> (k) & 1)
#define lg2(x) (31 - __builtin_clz(x))
#define LG2(x) (63 - __builtin_clzll(x))
#define popcnt(x) __builtin_popcount(x)
#define mem(a, x) memset(a, x, sizeof(a))
#define req(i, l, r) for (int i(l), i##End(r); i < i##End; i = -~i)
#define rep(i, l, r) for (int i(l), i##End(r); i <= i##End; i = -~i)
#define per(i, r, l) for (int i(r), i##End(l); i >= i##End; i = ~-i)
// #define FILERR
#ifdef JYR
#include "debug.h"
#ifdef FILERR
auto filerr = fopen("Test.err", "w");
#else
auto filerr = stderr;
#endif
#define errs(x) fputs(x "\n", filerr)
#define errm(x, ...) fprintf(filerr, x, ##__VA_ARGS__)
#else
#define dbg(...) 0
#define errs(x) 0
#define errm(x, ...) 0
#endif
template<typename T, typename U> void chkmx(T &_a, U _b) { if (_a < _b) _a = _b; }
template<typename T, typename U> void chkmn(T &_a, U _b) { if (_b < _a) _a = _b; }
bool Mbe;
struct FastIO {
char buf[1 << 20], *p1, *p2;
char puf[1 << 20], *pf;
FastIO() : p1(buf), p2(buf), pf(puf) {}
~FastIO() { fwrite(puf, 1, pf - puf, stdout); }
char gc() {
if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin);
return p1 == p2 ? EOF : *p1++;
}
bool blank(char c) { return c == ' ' || c == '\r' || c == '\n' || c == '\t'; }
char rd() {
char c = gc(); while (blank(c)) c = gc();
return c;
}
template<typename T> T rd() {
T x = 0; int f = 0; char c = gc();
while (!isdigit(c)) f = (c == '-'), c = gc();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c - '0'), c = gc();
return f ? -x : x;
}
int rds(char *s) {
char c = gc(), *S = s;
while (blank(c)) c = gc();
while (!blank(c) && c != EOF) *s++ = c, c = gc();
return *s = 0, abs(s - S);
}
int rdl(char *s) {
char c = gc(), *S = s;
while (c == '\r' || c == '\n') c = gc();
while (c != '\r' && c != '\n' && c != EOF) *s++ = c, c = gc();
return *s = 0, abs(s - S);
}
void rd(char &c) { c = rd(); }
void rd(char *s) {
char c = gc();
while (blank(c)) c = gc();
if (c == EOF) { *s = 0; return; }
while (!blank(c) && c != EOF) *s++ = c, c = gc();
*s = 0;
}
template<typename T> void rd(T &x) {
x = 0; int f = 0; char c = gc();
while (!isdigit(c)) f = (c == '-'), c = gc();
while (isdigit(c)) x = (x << 1) + (x << 3) + (c - '0'), c = gc();
if (f) x = -x;
}
template<typename T, typename... Ts>
void rd(T& x, Ts&... xs) { rd(x), rd(xs...); }
void pc(const char &c) {
if (pf - puf == 1 << 20) fwrite(pf = puf, 1, 1 << 20, stdout);
*pf++ = c;
}
void prt(char c) { pc(c); }
void prt(char* s) { while (*s) pc(*s++); }
void prt(const char* s) { while (*s) pc(*s++); }
template<typename T> void prt(T x) {
static int st[41], tp = 0;
if (x == 0) { pc('0'); return; }
if (x < 0) x = -x, pc('-');
while (x) st[++tp] = x % 10, x /= 10;
while (tp) pc(st[tp--] + '0');
}
template<typename T> void prt(T *x) { while (*x) pc(*x++); }
template<typename T, typename... Ts>
void prt(T x, Ts... xs) { prt(x), prt(xs...); }
void prts(const char *s, char c = '\n') {
while (*s) pc(*s++);
if (c) pc(c);
}
} IO;
#define rd IO.rd
#define rdl IO.rdl
#define ri rd<int>()
#define rl rd<ll>()
#define prt IO.prt
#define prs IO.prts
#define edl IO.pc('\n')
#define MC
#define N 100005
#define mod 998244353
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pli pair<ll, int>
#define vli vector<pli>
#define pb pop_back
int TID, n, m;
ll ans;
ll a[N];
int p[63][N];
int vt[N], tp;
vli st;
vector<vli> res;
bool vs[N];
ll dfs1(ll xs, int k, bool fg) {
if (k < 0) return 0;
ll K = BIT(k) - 1;
if (bin(xs, k)) {
rep(_, 1, n) if (int i = p[k][_]; !vs[i] && !bin(a[i], k)) {
vs[i] = 1;
ll x = K + 1 - (a[i] & K) + dfs1(xs ^ (a[i] & K), k - 1, 1);
return vs[i] = 0, x;
}
if (fg) return K + 1 + dfs1(xs, k - 1, fg);
return INF;
}
ll x = dfs1(xs, k - 1, fg);
if (!fg) rep(_, 1, n) if (int i = p[k][_]; !vs[i]) {
if (bin(a[i], k)) break;
rep(__, _ + 1, n) if (int j = p[k][__]; !vs[j]) {
if (bin(a[j], k)) break;
vs[i] = vs[j] = 1;
chkmn(x, K + 1 - (a[i] & K) - (a[j] & K) + K + 1
+ dfs1(xs ^ (a[i] & K) ^ (a[j] & K), k - 1, 1));
return vs[i] = vs[j] = 0, x;
}
}
return x;
}
bool dfs2(ll xs, int k, bool fg, ll su) {
if (su > ans) return 0;
if (k < 0) {
res.eb(st);
if (res.size() == m) throw 0;
return 1;
}
ll K = BIT(k) - 1;
if (bin(xs, k)) {
rep(_, 1, n) if (int i = p[k][_]; !vs[i]) {
if (bin(a[i], k)) break;
vs[i] = 1, st.eb(K + 1 - (a[i] & K), i), vt[++tp] = i;
bool tg = dfs2(xs ^ (a[i] & K), k - 1, 1, su + K + 1 - (a[i] & K));
vs[i] = 0, st.pb(), tp--;
if (!tg) break;
}
if (fg) {
rep(_, 1, tp) {
int i = vt[_];
st.eb(K + 1, i);
bool tg = dfs2(xs, k - 1, fg, su + K + 1);
st.pb();
if (!tg) break;
}
}
return 1;
}
dfs2(xs, k - 1, fg, su);
int t = n + 1;
if (!fg) rep(_, 1, n) if (int i = p[k][_]; !vs[i]) {
if (bin(a[i], k) || _ >= t) break;
rep(__, _ + 1, n) if (int j = p[k][__]; !vs[j]) {
if (bin(a[j], k)) break;
ll x = K + 1 - (a[i] & K), y = K + 1 - (a[j] & K);
vs[i] = vs[j] = 1, st.eb(x, i), st.eb(y, j), vt[++tp] = i, vt[++tp] = j;
bool tg = dfs2(xs ^ (a[i] & K) ^ (a[j] & K), k - 1, 1, su + x + y);
vs[i] = vs[j] = 0, st.pb(), st.pb(), ----tp;
if (!tg) { chkmn(t, __); break; }
}
}
return 1;
}
void mslv() {
rd(n, m), st.clear(), res.clear();
ll xs = 0;
rep(i, 1, n) xs ^= a[i] = rl;
rep(k, 0, 60) {
rep(i, 1, n) p[k][i] = i;
ll K = BIT(k) - 1;
sort(p[k] + 1, p[k] + n + 1, [&](int i, int j) {
return (bin(a[i], k) ? -1 : a[i] & K)
> (bin(a[j], k) ? -1 : a[j] & K);
});
}
ans = dfs1(xs, 60, 0);
try { dfs2(xs, 60, 0, 0); }
catch(...) {}
prt(ans, '\n', res.size(), '\n');
for (auto ve : res) {
sort(all(ve), [](pli x, pli y) { return x.se < y.se; });
vli vc;
for (auto [x, i] : ve) {
if (vc.empty() || vc.back().se != i) vc.eb(x, i);
else vc.back().fi += x;
}
prt(vc.size(), '\n');
for (auto [x, i] : vc) prt(i, ' '); edl;
for (auto [x, i] : vc) prt(x, ' '); edl;
}
}
void mprw() {}
bool Med;
int main() {
#ifdef JYR
errs("Running!");
freopen("Test.in", "r", stdin);
freopen("Test.out", "w", stdout);
#endif
mprw();
#ifdef MC
int _; rd(TID, _);
while (_--) mslv();
#else
mslv();
#endif
errm("%.3lfMB %.0lfms\n", abs(&Med - &Mbe) / 1048576., clock() * 1000. / CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 12ms
memory: 30424kb
input:
1 10000 2 1 324097321 555675086 2 1 304655177 991244276 2 1 9980291 383616352 2 1 1071036550 795625380 2 1 682098056 68370721 2 1 969101726 685975156 2 1 973896269 354857775 2 1 196188000 606494155 2 1 754416123 467588829 2 1 495704303 558090120 2 1 618002000 491488050 2 1 741575237 9937018 2 1 1002...
output:
231577765 1 1 1 231577765 4557430888798830399 0 4557430888798830399 0 275411170 1 2 1 2 265730182 9680988 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 45574308887988...
result:
wrong answer jury has better answer
Subtask #2:
score: 12
Accepted
Test #2:
score: 12
Accepted
time: 0ms
memory: 30296kb
input:
2 5 5 2000 0 13 3 4 10 5 2000 0 3 9 1 11 5 2000 0 13 7 3 5 5 2000 0 1 13 9 2 5 2000 0 8 14 7 13
output:
0 1 0 0 1 0 2 2 2 2 3 1 1 2 3 5 1 1 3 2 2 1 5 1 2 1 5 3 2 1 2 4 5 1 1
result:
ok correct answer
Test #3:
score: 12
Accepted
time: 0ms
memory: 30292kb
input:
2 5 5 2000 0 4 14 5 7 5 2000 0 2 15 0 12 5 2000 0 1 14 0 5 5 2000 0 13 4 12 3 5 2000 0 10 10 1 11
output:
6 2 3 1 4 5 4 1 1 2 4 5 1 5 1 4 1 1 1 1 2 1 1 4 1 1 5 1 8 8 3 1 2 5 2 3 3 3 2 4 5 3 2 3 2 2 5 3 5 2 2 5 5 3 3 1 2 5 4 1 3 3 2 4 5 1 4 3 2 2 5 1 7 2 2 5 7 1 2 4 2 1 5 1 1 2 3 5 1 1 2 4 5 1 1 1 5 2 10 13 3 1 2 4 2 1 7 3 1 3 4 2 1 7 2 1 4 2 8 2 1 4 3 7 2 1 4 ...
result:
ok correct answer
Test #4:
score: 12
Accepted
time: 0ms
memory: 30252kb
input:
2 5 5 2000 0 6 15 10 1 5 2000 0 15 0 13 10 5 2000 0 5 7 5 1 5 2000 0 13 3 2 15 5 2000 0 2 4 7 0
output:
2 5 2 1 5 1 1 2 2 5 1 1 2 4 5 1 1 1 5 2 1 1 2 8 2 1 1 8 1 3 8 4 2 2 2 5 1 3 2 4 5 1 3 1 1 1 2 1 1 4 1 1 1 1 2 1 1 3 1 1 5 1
result:
ok correct answer
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 30800kb
input:
3 5 6 2000 0 45 517 811 107 132 6 2000 0 382 576 805 419 579 6 2000 0 379 809 441 331 67 6 2000 0 565 776 959 852 383 6 2000 0 613 383 829 47 441
output:
146 20 5 1 2 3 4 6 1 19 1 1 124 4 2 3 4 6 19 1 1 125 4 2 3 4 6 20 1 1 124 4 2 3 4 6 19 1 2 124 4 2 3 4 6 19 2 1 124 4 1 2 4 6 2 19 1 124 3 2 4 6 19 1 126 3 2 4 6 21 1 124 3 2 4 6 19 3 124 5 1 2 3 5 6 1 19 1 1 124 4 2 3 5 6 19 1 1 125 4 2 3 5 6 20 1 1 124 4 2 3 5 6 19 1 2 124...
result:
wrong answer invalid solution xor sum does not equal to 0 at test case 3
Subtask #4:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 226ms
memory: 30072kb
input:
4 257 100000 100 32768 65536 262144 32768 8388608 1048576 4 67108864 16384 32768 262144 8192 512 134217728 65536 4194304 262144 67108864 1024 262144 64 32 65536 2097152 268435456 1 2048 4194304 16777216 8 16384 2 2048 16777216 268435456 262144 1048576 8388608 16 268435456 2 128 4194304 262144 32768 ...
output:
303389274 100 13 4330 6806 12450 15412 16083 20338 30949 31755 45139 48217 59387 59608 74711 1048576 262144 33554432 16384 8 2048 2 512 4096 16 64 65536 268435456 13 4330 6806 12450 15412 16083 20338 31755 45139 48217 59387 59608 74711 86656 1048576 262144 33554432 16384 8 2048 512 4096 16 64 655...
result:
wrong answer Integer 74711 violates the range [1, 17]
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 27ms
memory: 30344kb
input:
5 10000 10 1 0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 10 1 0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 10 1 0 1073741823 1073741823 1073741823 1073741823 1073741823 1073741823 1073741...
output:
1073741823 1 1 1 1073741823 1073741825 1 3 1 2 3 1073741823 1 1 1073741825 1 3 1 4 5 1073741823 1 1 1073741825 1 3 1 6 7 1073741823 1 1 1073741825 1 3 1 8 9 1073741823 1 1 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 4557430888798830399 0 45574308...
result:
wrong answer jury has better answer
Subtask #6:
score: 0
Wrong Answer
Test #22:
score: 0
Wrong Answer
time: 1ms
memory: 30420kb
input:
6 23 1000 10 0 357293452 452461848 986047039 546588280 762710079 767831017 39741545 416114273 515599366 1018969624 603342125 928112286 1053016142 240953466 533088067 1028134429 504727014 371307863 834428873 968387878 478550336 1047217797 1046651542 777749850 866989319 92995163 251915198 363285573 10...
output:
264227 10 12 134 187 203 355 565 569 673 786 876 955 996 999 5 1 2638 9 531 1 1 697 251113 10 5226 3995 12 134 187 203 355 542 565 673 786 876 955 996 999 5 1 2638 9 1 531 1 697 251113 10 5226 3995 12 134 187 203 355 543 565 673 786 876 955 996 999 5 1 2638 9 1 531 1 697 251113 10 5226 3995 12...
result:
wrong answer Integer 876 violates the range [1, 10]
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #8:
0%