This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "Memory2_lib.h"
#include <bits/stdc++.h>
using namespace std;
void Solve(int t, int n) {
vector<int> val(2*n, -1), cnt(n, 0);
vector<vector<int>> st(n);
priority_queue<int> pq;
for (int i=0; i<2*n; i++) pq.emplace(i);
int lx;
while (pq.size()) {
int x=pq.top();
pq.pop();
while (pq.size()) {
int y=pq.top();
pq.pop();
int r=Flip(x, y);
if (st[r].size()+cnt[r]==2) {
val[x]=r;
pq.emplace(y);
for (auto &i:st[r]) pq.emplace(i);
for (int i=0; i<n; i++) {
if (i!=r) for (auto &j:st[i]) val[j]=i, cnt[i]++;
st[i].clear();
}
break;
}
st[r].emplace_back(y);
}
lx=x;
}
for (int i=0; i<2*n; i++) if (val[i]!=-1) st[val[i]].emplace_back(i);
for (int i=0; i<n; i++) {
if (st[i].size()==1) st[i].emplace_back(lx);
Answer(st[i][0], st[i][1], i);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |