답안 #55437

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55437 2018-07-07T10:13:35 Z SpaimaCarpatilor Memory 2 (JOI16_memory2) C++17
60 / 100
3 ms 612 KB
#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

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];
                                                ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 520 KB Output is correct
6 Correct 2 ms 520 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 612 KB Output is correct
2 Correct 3 ms 612 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 3 ms 612 KB Output is correct
5 Correct 2 ms 612 KB Output is correct
6 Correct 2 ms 612 KB Output is correct
7 Correct 2 ms 612 KB Output is correct
8 Correct 3 ms 612 KB Output is correct
9 Correct 3 ms 612 KB Output is correct
10 Correct 2 ms 612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 612 KB Wrong Answer[3]
2 Halted 0 ms 0 KB -