QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#137465 | #2353. Maharajas are Going Home | kiwiHM# | WA | 105ms | 333644kb | C++14 | 2.2kb | 2023-08-10 12:58:33 | 2023-08-10 12:58:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2005;
class Mex{
public:
int mex;
int vis[maxn * 5];
Mex(){ mex = 0, memset(vis, 0, sizeof(vis)); }
inline int query(){ return mex; }
inline void insert(int x){
vis[x] = 1;
for(; vis[mex]; ++mex);
return;
}
} f[maxn], g[maxn], h[maxn * 2];
const int dx[2] = {-1, -2};
const int dy[2] = {-2, -1};
const int n = 2000;
int a[maxn][maxn];
inline void precalc(){
for(int i = 1; i <= n; ++i){ for(int j = 1; j <= n; ++j){
a[i][j] = max(f[i].query(), max(g[j].query(), h[i - j + n].query()));
for(int k = 0; k < 2; ++k){
int x = i + dx[k], y = j + dy[k];
if(x > 0 && y > 0 && a[x][y] == a[i][j]) ++a[i][j];
}
for(int k = 0; k < 2; ++k){
int x = i + dx[k], y = j + dy[k];
if(x > 0 && y > 0 && a[x][y] == a[i][j]) ++a[i][j];
}
f[i].insert(a[i][j]), g[j].insert(a[i][j]), h[i - j + n].insert(a[i][j]);
// if(i <= 5 && j <= 5) printf("%d ", a[i][j]);
} /* if(i <= 5) puts(""); */ }
return;
}
const int maxm = 15;
int m;
int X[maxm], Y[maxm];
inline void solve(){
scanf("%d", &m);
int xsum = 0;
for(int i = 0; i < m; ++i) scanf("%d%d", X + i, Y + i), xsum ^= a[X[i]][Y[i]];
// printf("xsum = %d\n", xsum);
if(!xsum) puts("-1 -1 -1");
else{
pair<int, pair<int, int> > ans = make_pair(0x3f3f3f3f, make_pair(0x3f3f3f3f, 0x3f3f3f3f));
for(int i = 0; i < m; ++i){
int nxsum = xsum ^ a[X[i]][Y[i]];
for(int j = 1; j <= X[i]; ++j) if(!(nxsum ^ a[j][Y[i]]))
ans = min(ans, make_pair(i, make_pair(j, Y[i])));
for(int j = 1; j <= Y[i]; ++j) if(!(nxsum ^ a[X[i]][j]))
ans = min(ans, make_pair(i, make_pair(X[i], j)));
for(int j = 1; j <= min(X[i], Y[i]) - 1; ++j) if(!(nxsum ^ a[X[i] - j][Y[i] - j]))
ans = min(ans, make_pair(i, make_pair(X[i] - j, Y[i] - j)));
for(int j = 0; j < 2; ++j)
if(X[i] + dx[j] > 0 && Y[i] + dy[j] > 0 && !(nxsum ^ a[X[i] + dx[j]][Y[i] + dy[j]]))
ans = min(ans, make_pair(i, make_pair(X[i] + dx[j], Y[i] + dy[j])));
}
printf("%d %d %d\n", ans.first + 1, ans.second.first, ans.second.second);
}
}
int main(){
precalc();
int T;
for(scanf("%d", &T); T--; solve());
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 87ms
memory: 333644kb
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: 105ms
memory: 333292kb
input:
1 1 1 1
output:
-1 -1 -1
result:
ok single line: '-1 -1 -1'
Test #3:
score: 0
Accepted
time: 97ms
memory: 333508kb
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 1 1 1 2 4 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 1 1 1 2 4 -1 -1 -1 1 4 2 1 1 1 -1 -1 -1 1 2 4 1 2 4 -1 -1 -1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 4 1 2 4 1 1 1 1 1 1 -1 -1 -1 1 2 4 1 2 4 1 2 4 1 2 4 1 1 1 1 1 1 1 2 4 1 2 4 1 1 1 1 2 4 1 1 1 1 1 1 1 1 1 1 1 1 -1 -1 -1 1 4 2 1 2 4 1 1 1 ...
result:
ok 100 lines
Test #4:
score: 0
Accepted
time: 104ms
memory: 333412kb
input:
100 1 10 10 1 9 8 1 2 5 1 9 10 1 3 6 1 1 2 1 1 2 1 10 6 1 6 4 1 10 8 1 7 1 1 1 3 1 4 2 1 2 1 1 1 5 1 10 4 1 6 7 1 7 2 1 7 1 1 10 2 1 4 1 1 9 3 1 9 8 1 2 2 1 2 3 1 1 9 1 3 3 1 3 9 1 9 4 1 2 2 1 6 8 1 1 3 1 3 10 1 7 6 1 10 10 1 7 8 1 2 7 1 5 3 1 8 6 1 4 4 1 9 5 1 5 1 1 2 1 1 4 1 1 3 1 1 1 9 1 5 7 1 9 ...
output:
1 1 1 1 6 5 1 2 4 1 5 6 1 2 4 1 1 1 1 1 1 1 5 6 1 2 4 1 4 2 1 1 1 1 1 1 -1 -1 -1 1 1 1 1 1 1 1 2 4 1 3 7 1 4 2 1 1 1 1 4 2 1 1 1 1 7 3 1 6 5 1 1 1 1 1 1 1 1 1 1 1 1 1 3 7 1 2 4 1 1 1 1 2 4 1 1 1 1 3 7 1 5 6 1 1 1 1 5 6 1 2 4 1 4 2 1 4 2 1 1 1 1 6 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 4 1 7 3 1 4 2 1 3...
result:
ok 100 lines
Test #5:
score: -100
Wrong Answer
time: 86ms
memory: 333512kb
input:
100 2 100 100 87 49 2 38 68 61 81 2 41 26 82 40 2 15 92 26 90 2 87 50 76 15 2 41 85 57 30 2 52 7 73 19 2 78 15 95 71 2 51 72 5 34 2 20 83 74 1 2 63 42 74 75 2 97 96 35 72 2 17 84 98 52 2 84 37 50 5 2 55 26 62 4 2 67 13 45 64 2 11 93 45 58 2 39 9 64 26 2 49 17 40 18 2 38 51 34 2 2 30 6 50 60 2 19 24 ...
output:
1 20 20 2 43 63 2 64 40 1 15 80 2 1 15 1 41 10 2 66 19 1 55 15 1 51 18 2 65 1 2 17 18 1 46 45 1 17 42 1 53 6 2 37 4 1 38 13 1 11 40 2 55 26 1 37 17 1 38 33 2 38 48 1 15 20 1 20 43 1 9 18 1 23 84 2 87 43 1 2 14 1 50 61 1 5 11 1 5 25 2 43 30 2 60 25 2 2 47 1 41 10 1 32 29 1 12 61 1 42 58 2 12 30 1 14 ...
result:
wrong answer 1st lines differ - expected: '1 91 91', found: '1 20 20'