QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#868033 | #9685. nim 游戏 | w4p3r | 0 | 230ms | 47328kb | C++20 | 5.4kb | 2025-01-24 11:19:30 | 2025-01-24 11:19:30 |
Judging History
你现在查看的是最新测评结果
- [2025-01-27 09:19:35]
- hack成功,自动添加数据
- (/hack/1490)
- [2025-01-27 08:19:11]
- hack成功,自动添加数据
- (/hack/1488)
- [2025-01-26 18:55:44]
- hack成功,自动添加数据
- (/hack/1475)
- [2025-01-24 11:19:30]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define N 100010
const ll inf = 4e18;
int n, m, m0;
ll k;
vector<vector<pair<int, ll>>>ans;
ll a[N], b[N];
bool vst[N];
int p[61][N];
vector<pair<int, ll>>Add;
vector<int>Ids;
bool cmp(int x, int y) {return b[x] > b[y];}
bool dfs(ll Xorsum, int num, int pos, ll used)
{
if (used > k)return 0;
if (pos < 0)
{
vector<pair<int, ll>>New, Temp;
Temp = Add; sort(Temp.begin(), Temp.end());
int k = Add.size();
for (int i = 0; i < k; i ++)
{
if (i == 0 || Temp[i].first != New.back().first) New.push_back(Temp[i]);
else New.back().second += Temp[i].second;
}
ans.push_back(New); ++ m0;
return 1;
}
int t = (Xorsum >> pos) & 1;
int flag = 0;
if (t == 0)
{
flag |= dfs(Xorsum, num, pos - 1, used);
if (m0 == m) return 1;
if ((!num) && (n & 1))
{
int fl = 1;
for (int i = 1; i <= n; i ++)
{
int x = p[pos][i];
if (vst[x] || ((a[x] >> pos) & 1)) continue;
for (int j = i + 1; j <= n; j ++)
{
int y = p[pos][j];
if (vst[y] || ((a[y] >> pos) & 1)) continue;
vst[x] = vst[y] = 1;
ll wx = (a[x] & ((1LL << pos) - 1)), wy = (a[y] & ((1LL << pos) - 1));
Add.push_back({x, (1LL << pos) - wx}); Add.push_back({y, (1LL << pos) - wy});
Ids.push_back(x); Ids.push_back(y);
fl = dfs(Xorsum ^ wx ^ wy, num + 2, pos - 1, used + (2LL << pos) - wx - wy);
flag |= fl;
Add.pop_back(); Add.pop_back();
Ids.pop_back(); Ids.pop_back();
vst[x] = vst[y] = 0;
if (m0 == m) return 1;
if (!fl)break;
}
if (!fl)break;
}
}
}
else if (t == 1)
{
int fl = 1;
for (int i = 1; i <= n; i ++)
{
int x = p[pos][i];
if (vst[x] || ((a[x] >> pos) & 1)) continue;
vst[x] = 1; ll wx = (a[x] & ((1LL << pos) - 1));
Add.push_back({x, (1LL << pos) - wx}); Ids.push_back(x);
fl = dfs(Xorsum ^ wx ^ (1LL << pos), num + 1, pos - 1, used + (1LL << pos) - wx);
flag |= fl;
Add.pop_back();
Ids.pop_back();
vst[x] = 0;
if (m0 == m) return 1;
if (!fl)break;
}
if (fl && num)
{
for (auto x : Ids)
{
Add.push_back({x, (1LL << pos)});
fl = dfs(Xorsum ^ (1LL << pos), num, pos - 1, used + (1LL << pos));
Add.pop_back(); flag |= fl;
if (m0 == m) return 1;
if (!fl) break;
}
}
}
return flag;
}
ll sol(ll Xorsum, int num, int pos)
{
if (pos == -1) return 0;
ll ans = 4e18;
int t = (Xorsum >> pos) & 1;
int flag = 0;
if (t == 0)
{
ans = min(ans, sol(Xorsum, num, pos - 1));
if (!num)
{
bool flag = 0;
for (int i = 1; i <= n; i ++)
{
int x = p[pos][i];
if (vst[x] || ((a[x] >> pos) & 1)) continue;
for (int j = i + 1; j <= n; j ++)
{
int y = p[pos][j];
if (vst[y] || ((a[y] >> pos) & 1)) continue;
vst[x] = vst[y] = 1;
ll wx = (a[x] & ((1LL << pos) - 1)), wy = (a[y] & ((1LL << pos) - 1));
ans = min((2LL << pos) - wx - wy + sol(Xorsum ^ wx ^ wy, num + 2, pos - 1), ans);
vst[x] = vst[y] = 0;
flag = 1; break;
}
if (flag)break;
}
}
}
else if (t == 1)
{
bool flag = 0;
for (int i = 1; i <= n; i ++)
{
int x = p[pos][i];
if (vst[x] || ((a[x] >> pos) & 1)) continue;
vst[x] = 1;
ll wx = (a[x] & ((1LL << pos) - 1));
ans = min(ans, (1LL << pos) - wx + sol(Xorsum ^ wx ^ (1LL << pos), num + 1, pos - 1));
vst[x] = 0;
flag = 1; break;
}
if (!flag && num)
{
ans = min(ans, (1LL << pos) + sol(Xorsum ^ (1LL << pos), num, pos - 1));
}
}
return ans;
}
void sol()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++) cin >> a[i];
for (int j = 60; j >= 0; j --)
{
for (int i = 1; i <= n; i ++)p[j][i] = i;
for (int i = 1; i <= n; i ++)
{
if ((a[i] >> j) & 1)b[i] = -1;
else b[i] = (a[i] & ((1LL << j) - 1));
}
sort(p[j] + 1, p[j] + n + 1, cmp);
}
ll Xorsum = 0;
for (int i = 1; i <= n; i ++) Xorsum ^= a[i];
k = sol(Xorsum, 0, 60);
dfs(Xorsum, 0, 60, 0);
cout << 0 << '\n';
cout << 0 << '\n';
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int c, T; cin >> c >> T;
while (T --) sol();
return 0;
}
/*
1 1
5 10
15 15 7 5 3
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 135ms
memory: 28728kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer jury has worse answer? check your output.
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 28264kb
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 0 0 0 0 0 0 0 0 0
result:
wrong answer jury has worse answer? check your output.
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Time Limit Exceeded
Test #8:
score: 0
Time Limit Exceeded
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:
result:
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 230ms
memory: 28600kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer jury has worse answer? check your output.
Subtask #6:
score: 0
Wrong Answer
Test #22:
score: 0
Wrong Answer
time: 74ms
memory: 47328kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer jury has worse answer? check your output.
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #8:
0%