#include "Memory2_lib.h"
#include <bits/stdc++.h>
int Flip(int I, int J);
void Answer(int I, int J, int X);
using namespace std;
int ret[110];
int cnt[110];
int chk[110];
vector<int> ans[110];
void Solve(int T, int N) {
mt19937 gen(1020301);
uniform_int_distribution<int> dis(0, 1'000'000'000);
int r = 2 * N;
int ppv = -1, pre = -1;
while (r>0) {
if (r == 2) {
int x = -1, y = -1;
for (int i=0; i<2*N; i++) {
if (!chk[i]) {
if (x == -1) x = i;
else y = i;
}
}
ans[Flip(x, y)] = {x, y};
break;
}
int idx = dis(gen) % (r - (ppv != -1));
int pv;
for (int i=0; i<2*N; i++) {
if (!chk[i] && i != ppv) {
if (idx == 0) {
pv = i;
break;
}
idx --;
}
}
for (int i=0; i<N; i++) cnt[i] = 0;
if (ppv != -1) {
ret[ppv] = pre;
cnt[pre] ++;
}
for (int i=0; i<2*N; i++) {
if (pv == i || ppv == i || chk[i]) continue;
ret[i] = Flip(pv, i);
cnt[ret[i]] ++;
}
int cur = -1;
for (int i=0; i<N; i++) {
if (cnt[i] & 1) {
cur = i;
break;
}
}
if (cur == pre) {
ans[pre] = {ppv, pv};
chk[ppv] = 1;
chk[pv] = 1;
r -= 2;
ppv = -1;
pre = -1;
continue;
}
for (int i=0; i<2*N; i++) {
if (pv == i || chk[i]) continue;
if (ret[i] != cur) {
ans[ret[i]].push_back(i);
chk[i] = 1;
r --;
}
}
ppv = pv;
pre = cur;
}
for (int i=0; i<N; i++) {
//printf("%d %d\n", ans[i][0], ans[i][1]);
Answer(ans[i][0], ans[i][1], i);
}
return;
}
Compilation message
memory2.cpp: In function 'void Solve(int, int)':
memory2.cpp:49:26: warning: 'pv' may be used uninitialized in this function [-Wmaybe-uninitialized]
49 | ret[i] = Flip(pv, i);
| ~~~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |