# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
296855 |
2020-09-11T01:47:58 Z |
eggag32 |
Library (JOI18_library) |
C++17 |
|
415 ms |
4504 KB |
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include "library.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
const int mxN = 1005;
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
mt19937 rng((ll)std::chrono::steady_clock::now().time_since_epoch().count());
int pos[mxN][mxN];
vi g[mxN];
void Solve(int n){
if(n == 1){
vi ans = {1};
Answer(ans);
return;
}
int sz = n / 31; //the size of our guess bucket
int num = (n * (n - 1)) / 2;
int rem = 20000;
memset(pos, -1, sizeof(pos));
while((num + 1000) > rem){
vi vis(n, 0), cr;
rep(k, sz){
while(true){
int ind = rng() % n;
if(!vis[ind]){
vis[ind] = 1;
cr.pb(ind);
break;
}
}
}
int ans = Query(vis);
if(ans == sz){
rep(i, cr.size()) rep(j, cr.size()) if(i != j && pos[cr[i]][cr[j]] == -1){
num--;
pos[cr[i]][cr[j]] = 0;
pos[cr[j]][cr[i]] = 0;
}
}
rem--;
}
vi nw(n, 0);
pi prev = {-1, -1};
rep(i, n) rep(j, n) if(i != j && pos[i][j] == -1){
if(prev.fi != -1) nw[prev.fi] = nw[prev.se] = 0;
nw[i] = nw[j] = 1;
prev = mp(i, j);
int ans = Query(nw);
if(ans == 1) pos[i][j] = pos[j][i] = 1;
else pos[i][j] = pos[j][i] = 0;
}
//now we know all the comparisons so we can just reconstruct the answer
int st = -1;
rep(i, n){
rep(j, n){
if(pos[i][j] == 1) g[i].pb(j);
}
if(g[i].size() == 1) st = i;
}
vi ans;
ans.pb(st + 1);
int nxt = g[st][0];
repn(i, 1, n){
ans.pb(nxt + 1);
rep(j, g[nxt].size()){
if((ans[(int)ans.size() - 2] - 1) != g[nxt][j]){
nxt = g[nxt][j];
break;
}
}
}
Answer(ans);
return;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
4472 KB |
# of queries: 18336 |
2 |
Correct |
249 ms |
4352 KB |
# of queries: 18145 |
3 |
Correct |
277 ms |
4352 KB |
# of queries: 18993 |
4 |
Correct |
200 ms |
4344 KB |
# of queries: 18991 |
5 |
Correct |
229 ms |
4352 KB |
# of queries: 18989 |
6 |
Correct |
228 ms |
4352 KB |
# of queries: 18997 |
7 |
Correct |
265 ms |
4472 KB |
# of queries: 18998 |
8 |
Correct |
261 ms |
4352 KB |
# of queries: 18528 |
9 |
Correct |
228 ms |
4344 KB |
# of queries: 18999 |
10 |
Correct |
133 ms |
4352 KB |
# of queries: 8256 |
11 |
Correct |
0 ms |
288 KB |
# of queries: 0 |
12 |
Correct |
3 ms |
4352 KB |
# of queries: 1 |
13 |
Correct |
3 ms |
4352 KB |
# of queries: 3 |
14 |
Correct |
3 ms |
4352 KB |
# of queries: 6 |
15 |
Correct |
5 ms |
4352 KB |
# of queries: 105 |
16 |
Correct |
9 ms |
4352 KB |
# of queries: 351 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
4472 KB |
# of queries: 18336 |
2 |
Correct |
249 ms |
4352 KB |
# of queries: 18145 |
3 |
Correct |
277 ms |
4352 KB |
# of queries: 18993 |
4 |
Correct |
200 ms |
4344 KB |
# of queries: 18991 |
5 |
Correct |
229 ms |
4352 KB |
# of queries: 18989 |
6 |
Correct |
228 ms |
4352 KB |
# of queries: 18997 |
7 |
Correct |
265 ms |
4472 KB |
# of queries: 18998 |
8 |
Correct |
261 ms |
4352 KB |
# of queries: 18528 |
9 |
Correct |
228 ms |
4344 KB |
# of queries: 18999 |
10 |
Correct |
133 ms |
4352 KB |
# of queries: 8256 |
11 |
Correct |
0 ms |
288 KB |
# of queries: 0 |
12 |
Correct |
3 ms |
4352 KB |
# of queries: 1 |
13 |
Correct |
3 ms |
4352 KB |
# of queries: 3 |
14 |
Correct |
3 ms |
4352 KB |
# of queries: 6 |
15 |
Correct |
5 ms |
4352 KB |
# of queries: 105 |
16 |
Correct |
9 ms |
4352 KB |
# of queries: 351 |
17 |
Correct |
411 ms |
4472 KB |
# of queries: 18999 |
18 |
Correct |
403 ms |
4352 KB |
# of queries: 18994 |
19 |
Correct |
393 ms |
4472 KB |
# of queries: 18998 |
20 |
Correct |
415 ms |
4476 KB |
# of queries: 18998 |
21 |
Correct |
384 ms |
4472 KB |
# of queries: 18996 |
22 |
Correct |
393 ms |
4472 KB |
# of queries: 18996 |
23 |
Correct |
373 ms |
4472 KB |
# of queries: 18999 |
24 |
Correct |
301 ms |
4504 KB |
# of queries: 18997 |
25 |
Correct |
409 ms |
4472 KB |
# of queries: 18997 |
26 |
Correct |
406 ms |
4356 KB |
# of queries: 18999 |
27 |
Correct |
294 ms |
4472 KB |
# of queries: 18990 |
28 |
Correct |
410 ms |
4352 KB |
# of queries: 18999 |
29 |
Correct |
391 ms |
4472 KB |
# of queries: 18996 |
30 |
Correct |
405 ms |
4472 KB |
# of queries: 18998 |