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;
static int N, ans[109];
static map < pair < int, int >, int > mp;
static int f (int i, int j)
{
i --, j --;
if (i > j) swap (i, j);
if (mp.count ({i, j})) ;
else mp[{i, j}] = Flip (i, j);
return mp[{i, j}] + 1;
}
static void giveAnswer ()
{
for (int i=1; i<=N; i++)
{
int j1 = 0, j2 = 0;
for (int j=1; j<=2 * N; j++)
if (ans[j] == i)
{
if (j1 == 0) j1 = j;
else j2 = j;
}
Answer (j1 - 1, j2 - 1, i - 1);
}
}
void Solve (int T, int nn)
{
N = nn;
int a = 1, b = 2, c = 3;
for (int i=4; i<=2 * N; i++)
{
int ids[] = {a, b, c, i};
for (int j=0; j<4; j++)
{
int mi = N + 1, ma = 0;
for (int k=0; k<4; k++)
if (j != k)
{
int curr = f (ids[j], ids[k]);
if (curr < mi) mi = curr;
if (curr > ma) ma = curr;
}
if (mi == ma)
{
ans[ids[j]] = mi;
if (j == 0) a = i;
else
if (j == 1) b = i;
else
if (j == 2) c = i;
break;
}
}
}
if (f (a, b) == f (a, c)) ans[a] = f (a, b), ans[b] = ans[c] = f (b, c);
else
if (f (a, b) == f (b, c)) ans[b] = f (a, b), ans[a] = ans[c] = f (a, c);
else ans[c] = f (b, c), ans[a] = ans[b] = f (a, b);
giveAnswer ();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |