QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137331 | #2353. Maharajas are Going Home | Team_name# | WA | 225ms | 41584kb | C++20 | 2.7kb | 2023-08-10 10:34:08 | 2023-08-10 10:34:11 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define _debugVar(x) { cerr << "* "#x" = " << x << endl; }
#define _debugHere { fprintf(stderr, "* Passing [%s] in Line %d\n", __FUNCTION__, __LINE__); }
using namespace std;
using LL = long long;
using PII = pair<int, int>;
const int N = 4005, Bias = 2001;
constexpr int INF = 0x3f3f3f3f;
int f[N][N];
void initSG(int n)
{
static bitset<N> S1[Bias], S2[Bias], S3[N];
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
int k = i-j+Bias;
if(i == 1 && j == 1) f[i][j] = 0;
else {
int x = -1, y = -1;
if(i-2 >= 1 && j-1 >= 1) x = f[i-2][j-1];
if(i-1 >= 1 && j-2 >= 1) y = f[i-1][j-2];
bitset<N> tmp = S3[k] | S1[i] | S2[j];
if(x > -1) tmp[x] = 1;
if(y > -1) tmp[y] = 1;
// for(int r = 0; true; r++)
// if(r != x && r != y &&
// !S3[k][r] && !S1[i][r] && !S2[j][r]) {
// f[i][j] = r;
// break;
// }
tmp.flip();
f[i][j] = tmp._Find_first();
// if(f[i][j] < min(f[i-1][j-1], min(f[i][j-1], f[i-1][j]))) _debugHere;
}
S3[k][f[i][j]] = true;
S1[i][f[i][j]] = true;
S2[j][f[i][j]] = true;
// if(i % 101 == 0 && j % 101 == 0) {
// fprintf(stderr, "SG(%d, %d) = %d\n", i, j, f[i][j]);
// _debugVar(i); _debugVar(j); _debugVar(f[i][j]);
// }
// if(f[i][j] != min(i, j)-1) _debugHere;
}
}
// for(int i = 1; i <= 20; i++) {
// fprintf(stderr, "%02d: ", i);
// for(int j = 1; j <= 20; j++) {
// fprintf(stderr, "%3d ", f[i][j]);
// }
// cerr << endl;
// }
}
int sg(int i, int j)
{
return f[i][j];
// return min(i, j)-1;
}
int n;
PII a[N];
int main()
{
// freopen("1.in", "r", stdin);
clock_t st_time = clock();
initSG(2000);
int totCases; cin >> totCases;
for(int curCase = 1; curCase <= totCases; curCase++) {
cin >> n;
int sum = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
sum ^= sg(a[i].first, a[i].second);
}
// _debugVar(sum);
if(sum == 0) {
puts("-1 -1 -1");
continue;
}
for(int i = 1; i <= n; i++) {
PII ans = PII(INF, INF);
auto [x, y] = a[i];
for(int j = 1; j < min(x, y); j++) {
if(sum^sg(x, y)^sg(x-j, y-j)) continue;
ans = min(ans, PII(x-j, y-j));
}
if(x-2 >= 1 && y-1 >= 1 && !(sum^sg(x, y)^sg(x-2, y-1)))
ans = min(ans, PII(x-2, y-1));
if(x-1 >= 1 && y-2 >= 1 && !(sum^sg(x, y)^sg(x-1, y-2)))
ans = min(ans, PII(x-1, y-2));
if(ans.first != INF) {
printf("%d %d %d\n", i, ans.first, ans.second);
break;
}
}
}
cerr << "time: " << (double)(clock()-st_time)/CLOCKS_PER_SEC << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 217ms
memory: 41584kb
input:
3 5 2 3 3 2 3 3 3 3 3 3 1 2 4 2 1 1 3 2
output:
3 1 1 -1 -1 -1 2 1 1
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 225ms
memory: 39716kb
input:
1 1 1 1
output:
-1 -1 -1
result:
ok single line: '-1 -1 -1'
Test #3:
score: -100
Wrong Answer
time: 216ms
memory: 39412kb
input:
100 1 5 5 1 1 5 1 5 4 1 4 4 1 2 2 1 5 3 1 4 5 1 2 4 1 4 1 1 3 2 1 3 2 1 1 4 1 2 5 1 4 2 1 5 3 1 5 5 1 4 2 1 3 4 1 3 4 1 4 2 1 3 1 1 1 5 1 1 4 1 4 1 1 4 5 1 2 5 1 5 1 1 4 1 1 2 4 1 2 5 1 3 4 1 2 5 1 5 4 1 4 4 1 2 3 1 3 4 1 5 4 1 1 3 1 3 4 1 1 5 1 5 1 1 2 3 1 3 1 1 1 1 1 5 2 1 2 5 1 1 4 1 3 3 1 4 3 1 ...
output:
1 1 1 1 4 2 1 1 1 1 1 1 1 4 2 1 2 4 -1 -1 -1 1 1 1 1 1 1 -1 -1 -1 1 4 2 1 1 1 -1 -1 -1 -1 -1 -1 1 2 4 -1 -1 -1 1 4 2 1 1 1 1 1 1 1 4 2 1 1 1 -1 -1 -1 1 1 1 1 1 1 1 1 1 1 1 1 -1 -1 -1 1 1 1 -1 -1 -1 1 4 2 -1 -1 -1 1 1 1 1 4 2 1 1 1 1 2 4 1 1 1 1 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 2 4 1 1 1 1 1 1 -1 -1 -1 ...
result:
wrong answer 2nd lines differ - expected: '1 1 1', found: '1 4 2'