#include "chameleon.h"
#include <bits/stdc++.h>
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
using namespace std;
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 2e3 + 11;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 333;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;
bool used[N], was[N][N];
map < vi, int > Was;
vi tmp, v[N];
int l[N];
void ans (int x, int y) {
if (x > y)
swap(x, y);
if (!was[x][y])
Answer(x, y);
was[x][y] = 1;
}
int query (int x, int y, int z = -1) {
tmp.clear();
tmp.pb(x);
tmp.pb(y);
if (z > -1)
tmp.pb(z);
sort(all(tmp));
if (Was.count(tmp))
return Was[tmp];
return Was[tmp] = Query(tmp);
}
void Solve(int n) {
for (int i = 1; i <= n + n; ++i) {
for (int j = 1; j <= n + n; ++j)
if (j != i && query(i, j) == 1)
v[i].pb(j);
if (sz(v[i]) == 1) {
used[i] = used[v[i][0]] = 1;
ans(i, v[i][0]);
} else {
assert(sz(v[i]) == 3);
for (int j = 0; j < 3; ++j) {
int a = -1, b = -1;
for (int jj = 0; jj < 3; ++jj)
if (j != jj) {
if (a == -1)
a = v[i][jj];
else
b = v[i][jj];
}
if (query(a, b, i) == 1) {
l[i] = v[i][j];
break;
}
assert(query(a, b, i) == 2);
}
assert(l[i]);
}
}
for (int i = 1; i <= n + n; ++i)
if (!used[i]) {
used[i] = 1;
for (int j = 0; j < 3; ++j)
if (v[i][j] == l[i]) {
swap(v[i][j], v[i][sz(v[i]) - 1]);
v[i].ppb();
break;
}
assert(sz(v[i]) == 2);
if (used[l[v[i][0]]] || l[v[i][0]] == i) {
ans(v[i][1], i);
used[v[i][1]] = 1;
} else {
assert(l[v[i][1]] == i || used[v[i][1]]);
ans(v[i][0], i);
used[v[i][0]] = 1;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Incorrect |
30 ms |
2684 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Incorrect |
5 ms |
384 KB |
Wrong Answer [6] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
512 KB |
Output is correct |
2 |
Incorrect |
5 ms |
512 KB |
Wrong Answer [5] |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Incorrect |
30 ms |
2684 KB |
Wrong Answer [3] |
4 |
Halted |
0 ms |
0 KB |
- |