Submission #55438

# Submission time Handle Problem Language Result Execution time Memory
55438 2018-07-07T10:49:21 Z SpaimaCarpatilor None (JOI16_memory2) C++17
100 / 100
3 ms 752 KB
#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
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 588 KB Output is correct
5 Correct 3 ms 624 KB Output is correct
6 Correct 3 ms 624 KB Output is correct
7 Correct 3 ms 624 KB Output is correct
8 Correct 2 ms 624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 624 KB Output is correct
2 Correct 3 ms 624 KB Output is correct
3 Correct 2 ms 624 KB Output is correct
4 Correct 2 ms 720 KB Output is correct
5 Correct 2 ms 720 KB Output is correct
6 Correct 2 ms 720 KB Output is correct
7 Correct 2 ms 720 KB Output is correct
8 Correct 2 ms 720 KB Output is correct
9 Correct 2 ms 720 KB Output is correct
10 Correct 2 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 720 KB Output is correct
2 Correct 2 ms 720 KB Output is correct
3 Correct 2 ms 720 KB Output is correct
4 Correct 2 ms 720 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 3 ms 752 KB Output is correct
7 Correct 3 ms 752 KB Output is correct
8 Correct 2 ms 752 KB Output is correct
9 Correct 3 ms 752 KB Output is correct
10 Correct 3 ms 752 KB Output is correct