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, a[109], b[109], f[109], ap[109];
static map < pair < int, int >, int > mp;
static int q (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 (a[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;
mp.clear ();
memset (ap, 0, sizeof (ap));
for (int i=1; i<=2 * N; i++)
if (ap[i] == 0)
{
memset (f, 0, sizeof (f));
int lst = -1;
for (int j=i + 1; j<=2 * N; j++)
if (ap[j] == 0)
{
b[j] = q (i, j);
if (++f[b[j]] == 3)
{
lst = j;
break;
}
}
if (lst == -1)
{
a[i] = N, ap[i] = 1;
for (int j=i + 1; j<=2 * N; j++)
if (ap[j] == 0)
a[j] = b[j], ap[j] = 1;
continue;
}
a[i] = b[lst], ap[i] = 1;
for (int j=i + 1; j<lst; j++)
if (ap[j] == 0 && b[j] != b[lst])
ap[j] = 1, a[j] = b[j];
}
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... |