#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
const int MAXN = 256;
const int MOD = 200007;
const int NIL = 0;
int v[MAXN + 1], vrez[MAXN];
int cand[MAXN + 1][MAXN + 1], nrc[MAXN + 1], fr[MAXN + 1], next1[MAXN + 1];
char frecv[MAXN + 1];
int rez2, maxrez;
int mod(int x) {
return x < 0 ? -x : x;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
static inline unsigned long long genrand() {
return uniform_int_distribution<unsigned long long>(0, (unsigned long long)-1)(rng) * 1243;
}
void solve(int n) {
int i, j, x, rez, nr4, nrz, rezi;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cand[i][j] = 1;
}
nrc[i] = n;
}
vector<int> q;
for (i = 1; i <= n; i++) {
while (nrc[i] > 1) {
nrz = n;
for (j = 1; j <= n; j++) {
fr[j] = 1;
}
q.clear();
for (j = 1; j < i; j++) {
q.push_back(v[j]);
fr[v[j]] = 0;
nrz--;
}
nr4 = mod(genrand()) % nrc[i] + 1;
x = 1;
while (nr4 > 0) {
nr4 -= cand[i][x];
x++;
}
x--;
q.push_back(x);//candidat random
fr[x] = 0;
nrz--;
//in q sunt indexate de la 0
rezi = i - 1;
for (j = i + 1; j <= n; j++) {
x = 1;
while (cand[j][x] == 0) {
x++;
}
if (nrc[j] > 1 || fr[x] == 0) {
nr4 = mod(genrand()) % nrz + 1;
x = 1;
while (nr4 > 0) {
nr4 -= fr[x];
x++;
}
x--;
} else {
rezi++;
}
q.push_back(x);
fr[x] = 0;
nrz--;
}
rez = query(q);
rez2++;
if (rez == rezi) {
//nu sunt pe pozitiile bune cei de la i la n
for (j = i; j <= n; j++) {
if (nrc[j] > 1 || cand[j][q[j - 1]] == 0) {
nrc[j] -= cand[j][q[j - 1]];
cand[j][q[j - 1]] = 0;
}
}
} else if (rez == n) {
return;
}
}
x = 1;
while (cand[i][x] == 0) {
x++;
}
v[i] = x;
for (j = i + 1; j <= n; j++) {
nrc[j] -= cand[j][v[i]];
cand[j][v[i]] = 0;
}
}
q.clear();
for (i = 1; i <= n; i++) {
q.push_back(v[i]);
}
query(q);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 29 |
2 |
Correct |
1 ms |
372 KB |
Correct! Number of queries: 1 |
3 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 23 |
4 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 18 |
5 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 33 |
6 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 28 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 29 |
2 |
Correct |
1 ms |
372 KB |
Correct! Number of queries: 1 |
3 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 23 |
4 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 18 |
5 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 33 |
6 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 28 |
7 |
Correct |
10 ms |
336 KB |
Correct! Number of queries: 600 |
8 |
Correct |
7 ms |
336 KB |
Correct! Number of queries: 600 |
9 |
Correct |
6 ms |
336 KB |
Correct! Number of queries: 500 |
10 |
Correct |
6 ms |
336 KB |
Correct! Number of queries: 500 |
11 |
Correct |
7 ms |
336 KB |
Correct! Number of queries: 500 |
12 |
Correct |
6 ms |
336 KB |
Correct! Number of queries: 500 |
13 |
Correct |
5 ms |
336 KB |
Correct! Number of queries: 500 |
14 |
Correct |
8 ms |
336 KB |
Correct! Number of queries: 600 |
15 |
Correct |
7 ms |
336 KB |
Correct! Number of queries: 600 |
16 |
Correct |
6 ms |
336 KB |
Correct! Number of queries: 500 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 29 |
2 |
Correct |
1 ms |
372 KB |
Correct! Number of queries: 1 |
3 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 23 |
4 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 18 |
5 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 33 |
6 |
Correct |
1 ms |
336 KB |
Correct! Number of queries: 28 |
7 |
Correct |
10 ms |
336 KB |
Correct! Number of queries: 600 |
8 |
Correct |
7 ms |
336 KB |
Correct! Number of queries: 600 |
9 |
Correct |
6 ms |
336 KB |
Correct! Number of queries: 500 |
10 |
Correct |
6 ms |
336 KB |
Correct! Number of queries: 500 |
11 |
Correct |
7 ms |
336 KB |
Correct! Number of queries: 500 |
12 |
Correct |
6 ms |
336 KB |
Correct! Number of queries: 500 |
13 |
Correct |
5 ms |
336 KB |
Correct! Number of queries: 500 |
14 |
Correct |
8 ms |
336 KB |
Correct! Number of queries: 600 |
15 |
Correct |
7 ms |
336 KB |
Correct! Number of queries: 600 |
16 |
Correct |
6 ms |
336 KB |
Correct! Number of queries: 500 |
17 |
Correct |
173 ms |
592 KB |
Correct! Number of queries: 3800 |
18 |
Correct |
152 ms |
592 KB |
Correct! Number of queries: 3700 |
19 |
Correct |
155 ms |
592 KB |
Correct! Number of queries: 3600 |
20 |
Correct |
197 ms |
592 KB |
Correct! Number of queries: 4000 |
21 |
Correct |
179 ms |
592 KB |
Correct! Number of queries: 3800 |
22 |
Correct |
191 ms |
592 KB |
Correct! Number of queries: 3700 |
23 |
Correct |
162 ms |
592 KB |
Correct! Number of queries: 3700 |
24 |
Correct |
213 ms |
592 KB |
Correct! Number of queries: 4000 |
25 |
Correct |
166 ms |
592 KB |
Correct! Number of queries: 3800 |
26 |
Correct |
180 ms |
592 KB |
Correct! Number of queries: 3900 |