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>
#define pb push_back
#define eb emplace_back
#define sz(V) ((int)(V).size())
using namespace std;
typedef pair<int, int> pii;
unordered_map<int, int> MP;
int A[555];
int ask(int a, int b) {
if(a > b) swap(a, b);
int key = (a<<10) + b;
auto it = MP.find(key);
if(MP.end() != it) return it -> second;
int ret = Flip(a, b);
MP[key] = ret;
return ret;
}
int hsh(int a, int b) { return (a<<10)|b; }
void rhsh(int k, int &a, int &b) { b = k&1023; a = k>>10; }
void Solve(int T, int N) {
vector<pii> V;
for(int i = 0; i < N*2; i += 2)
V.eb(hsh(i, i+1), ask(i, i+1));
for(int a, b, t; !V.empty();) {
a = b = -1;
for(int i = 0; i < sz(V); i++) for(int j = i+1; j < sz(V); j++)
if(V[i].second == V[j].second)
tie(a, b) = pii(i, j);
if(a < 0) break;
int n[2], m[2];
t = V[a].second;
rhsh(V[a].first, n[0], n[1]);
rhsh(V[b].first, m[0], m[1]);
V.erase(V.begin() + b);
V.erase(V.begin() + a);
for(int i = 0; i < 2; i++) for(int j = 0; j < 2; j++) {
if(ask(n[i], m[j]) != t) {
V.eb(hsh(n[i], m[j]), ask(n[i], m[j]));
A[n[!i]] = A[m[!j]] = t;
}
}
}
for(auto &v : V) {
int a, b; rhsh(v.first, a, b);
A[a] = A[b] = v.second;
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < N*2; j++) for(int k = j+1; k < N*2; k++)
if(A[j] == i && A[k] == i)
Answer(j, k, 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... |