QOJ.ac
QOJ
ID | Submission ID | Problem | Hacker | Owner | Result | Submit time | Judge time |
---|---|---|---|---|---|---|---|
#1490 | #869570 | #9685. nim 游戏 | team1377 | cooluo | Success! | 2025-01-27 09:19:11 | 2025-01-27 09:19:11 |
Details
Extra Test:
Wrong Answer
time: 0ms
memory: 28124kb
input:
9 1 7 10 7 7 7 6 2 2 3
output:
4 4 2 1 2 3 1 3 1 2 5 1 1 2 2 1 3 3 1 2 1 3 1 3
result:
wrong answer invalid solution xor sum does not equal to 0 at test case 1
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#869570 | #9685. nim 游戏 | cooluo | 97 | 1806ms | 40648kb | C++23 | 7.7kb | 2025-01-25 11:23:19 | 2025-01-27 09:19:46 |
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];
vi vt;
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] && !bin(a[i], k)) {
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) {
if (res.size() == m) return 0;
return res.eb(st), 1;
}
ll K = BIT(k) - 1;
bool bk = 0;
if (bin(xs, k)) {
rep(_, 1, n) if (int i = p[k][_]; !vs[i] && !bin(a[i], k)) {
vs[i] = 1, st.eb(K + 1 - (a[i] & K), i), vt.eb(i);
bool tg = dfs2(xs ^ (a[i] & K), k - 1, 1, su + K + 1 - (a[i] & K));
vs[i] = 0, st.pb(), vt.pb();
if (!tg) return bk; bk = 1;
}
if (fg) {
for (auto i : vt) {
st.eb(K + 1, i);
bool tg = dfs2(xs, k - 1, fg, su + K + 1);
if (st.pb(); !tg) return bk; bk = 1;
}
}
return bk;
}
bk = dfs2(xs, k - 1, fg, su);
rep(_, 1, n) if (int i = p[k][_]; !vs[i] && !bin(a[i], k)) {
rep(__, _ + 1, n) if (int j = p[k][__]; !vs[j] && !bin(a[j], k)) {
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.eb(i), vt.eb(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(), vt.pb(), vt.pb();
if (!tg) return bk; bk = 1;
}
}
return bk;
}
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);
dfs2(xs, 60, 0, 0);
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;
}