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], ramase[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;
break;
}
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];
if (a[i] == N - 1)
{
int j1 = 0, j2 = 0;
for (int j=i + 1; j<lst; j++)
if (b[j] == b[lst])
{
if (j1 == 0) j1 = j;
else j2 = j;
}
a[j1] = a[j2] = a[lst] = N;
if (q (j1, j2) == N) a[lst] = N - 1;
else
if (q (j1, lst) == N) a[j2] = N - 1;
else a[j1] = N - 1;
for (int j=lst + 1; j<=2 * N; j++)
if (ap[j] == 0)
a[j] = q (i, j);
break;
}
}
giveAnswer ();
}
Compilation message (stderr)
memory2.cpp:6:48: warning: 'ramase' defined but not used [-Wunused-variable]
static int N, a[109], b[109], f[109], ap[109], ramase[109];
^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |