#include<bits/stdc++.h>
#include"grader.h"
using namespace std;
const int maxn = 55;
int MAGIC = 7;
mt19937 rng(69420);
int n = 50;
vector<int> crr;
int cnt[maxn][maxn];
int pp[maxn][maxn];
vector<vector<int>> amon;
vector<int> perm;
void backtrack(int pos) {
if(pos == n+1){
amon.push_back(crr);
return;
}
for(int i = 0; i < n; i++){
if(crr[i]){
continue;
}
bool chk = 1;
for(int j = 0; j < MAGIC; j++){
int tmp = i - pp[j][pos];
tmp*=-1;
if(tmp < 0)tmp += n;
if(!cnt[j][tmp]){
chk = 0;
break;
}
}
if(!chk)continue;
for(int j = 0; j < MAGIC; j++){
int tmp = i - pp[j][pos];
tmp*=-1;
if(tmp < 0)tmp += n;
cnt[j][tmp]--;
}
crr[i] = pos;
backtrack(pos+1);
crr[i] = 0;
for(int j = 0; j < MAGIC; j++){
int tmp = i - pp[j][pos];
tmp*=-1;
if(tmp < 0)tmp += n;
cnt[j][tmp]++;
}
}
}
void solve (int N){
n = N;
ios::sync_with_stdio(false);
cin.tie(0);
crr.assign(n, 0);
for(int i = 1; i <= n; i++)perm.push_back(i);
shuffle(perm.begin(), perm.end(), rng);
vector<int> rd = perm;
for(int i = 0; i < MAGIC; i++){
shuffle(rd.begin(), rd.end(), rng);
for(int j = 0; j < n; j++)pp[i][rd[j]] = j;
for(int j = 0; j < n; j++){
cnt[i][j] = query(rd);
if(cnt[i][j] == n)return;
rd.push_back(rd[0]);
rd.erase(rd.begin());
}
}
backtrack(1);
query(amon[0]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Correct! Number of queries: 50 |
2 |
Correct |
0 ms |
460 KB |
Correct! Number of queries: 29 |
3 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 43 |
4 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 50 |
5 |
Correct |
1 ms |
472 KB |
Correct! Number of queries: 50 |
6 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 50 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Correct! Number of queries: 50 |
2 |
Correct |
0 ms |
460 KB |
Correct! Number of queries: 29 |
3 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 43 |
4 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 50 |
5 |
Correct |
1 ms |
472 KB |
Correct! Number of queries: 50 |
6 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 50 |
7 |
Correct |
2 ms |
460 KB |
Correct! Number of queries: 400 |
8 |
Correct |
4 ms |
460 KB |
Correct! Number of queries: 400 |
9 |
Correct |
2 ms |
464 KB |
Correct! Number of queries: 400 |
10 |
Correct |
5 ms |
344 KB |
Correct! Number of queries: 400 |
11 |
Correct |
2 ms |
464 KB |
Correct! Number of queries: 300 |
12 |
Correct |
3 ms |
464 KB |
Correct! Number of queries: 400 |
13 |
Correct |
3 ms |
460 KB |
Correct! Number of queries: 400 |
14 |
Correct |
3 ms |
460 KB |
Correct! Number of queries: 400 |
15 |
Correct |
3 ms |
468 KB |
Correct! Number of queries: 400 |
16 |
Correct |
8 ms |
464 KB |
Correct! Number of queries: 400 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Correct! Number of queries: 50 |
2 |
Correct |
0 ms |
460 KB |
Correct! Number of queries: 29 |
3 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 43 |
4 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 50 |
5 |
Correct |
1 ms |
472 KB |
Correct! Number of queries: 50 |
6 |
Correct |
1 ms |
464 KB |
Correct! Number of queries: 50 |
7 |
Correct |
2 ms |
460 KB |
Correct! Number of queries: 400 |
8 |
Correct |
4 ms |
460 KB |
Correct! Number of queries: 400 |
9 |
Correct |
2 ms |
464 KB |
Correct! Number of queries: 400 |
10 |
Correct |
5 ms |
344 KB |
Correct! Number of queries: 400 |
11 |
Correct |
2 ms |
464 KB |
Correct! Number of queries: 300 |
12 |
Correct |
3 ms |
464 KB |
Correct! Number of queries: 400 |
13 |
Correct |
3 ms |
460 KB |
Correct! Number of queries: 400 |
14 |
Correct |
3 ms |
460 KB |
Correct! Number of queries: 400 |
15 |
Correct |
3 ms |
468 KB |
Correct! Number of queries: 400 |
16 |
Correct |
8 ms |
464 KB |
Correct! Number of queries: 400 |
17 |
Execution timed out |
3064 ms |
720 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |