답안 #167310

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167310 2019-12-07T09:21:31 Z ho94949 Minerals (JOI19_minerals) C++17
100 / 100
75 ms 4176 KB
#include "minerals.h"
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 43000;

int DP[MAXN+1];
int x[MAXN+1];


bool is_in[2*MAXN];
int last = 0;
int Q(int x)
{
    is_in[x] = !is_in[x];
    return last = Query(x);
}


void recur(vector<int> A, vector<int> B)
{
    //for(auto x: A) cout << x << " "; cout << endl;
    //for(auto x: B) cout << x << " "; cout << endl;
    //cout << endl;
    assert(A.size() == B.size());
    int N = A.size();
    assert(N >= 1);
    if(N==1)
    {
        Answer(A[0], B[0]);
        return;
    }

    int M = x[N];
    
    vector<int> fA, fB, sA, sB;
    for(int i=0; i<M; ++i)
    {
        fA.push_back(A[i]);
        Q(A[i]);
    }
    bool is_fA_inside = is_in[A[0]];
    for(int i=M; i<N; ++i)
    {
        sA.push_back(A[i]);
    }
    int i = 0;
    while(fB.size() != fA.size() && sB.size() != sA.size())
    {
        int plast = last;
        Q(B[i]);
        if(is_fA_inside == (last == plast) )
            fB.push_back(B[i]);
        else
            sB.push_back(B[i]);
        ++i;
    }
    while(fB.size() != fA.size()) fB.push_back(B[i++]);
    while(sB.size() != sA.size()) sB.push_back(B[i++]);
    recur(fA, fB);
    recur(sA, sB);    
}

void init()
{
    DP[1] = 0;
    DP[2] = 2;
    x[2] = 1;
    for(int i=3; i<=MAXN; ++i)
    {
        int xa = x[i-1], xb = x[i-1]+1;
        int dpa = DP[xa] + DP[i-xa] + xa + i - 1;
        int dpb = DP[xb] + DP[i-xb] + xb + i - 1;
        if(dpa < dpb)
        {
            x[i] = xa; DP[i] = dpa;
        }
        else
        {
            x[i] = xb; DP[i] = dpb;
        }
    }
}


void Solve(int N) {
    init();
    vector<int> V, W;
    for(int i=1; i<=2*N; ++i)
    {
        int plast = last;
        Q(i);
        if(last != plast) V.push_back(i);
        else W.push_back(i);
    }
    recur(V, W);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 5 ms 760 KB Output is correct
3 Correct 8 ms 888 KB Output is correct
4 Correct 14 ms 1252 KB Output is correct
5 Correct 25 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 14 ms 1252 KB Output is correct
9 Correct 25 ms 1880 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1492 KB Output is correct
12 Correct 24 ms 1904 KB Output is correct
13 Correct 20 ms 1832 KB Output is correct
14 Correct 21 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 14 ms 1252 KB Output is correct
9 Correct 25 ms 1880 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1492 KB Output is correct
12 Correct 24 ms 1904 KB Output is correct
13 Correct 20 ms 1832 KB Output is correct
14 Correct 21 ms 1792 KB Output is correct
15 Correct 66 ms 3736 KB Output is correct
16 Correct 65 ms 3784 KB Output is correct
17 Correct 47 ms 3836 KB Output is correct
18 Correct 61 ms 3628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 14 ms 1252 KB Output is correct
9 Correct 25 ms 1880 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1492 KB Output is correct
12 Correct 24 ms 1904 KB Output is correct
13 Correct 20 ms 1832 KB Output is correct
14 Correct 21 ms 1792 KB Output is correct
15 Correct 66 ms 3736 KB Output is correct
16 Correct 65 ms 3784 KB Output is correct
17 Correct 47 ms 3836 KB Output is correct
18 Correct 61 ms 3628 KB Output is correct
19 Correct 68 ms 3844 KB Output is correct
20 Correct 66 ms 3892 KB Output is correct
21 Correct 49 ms 3780 KB Output is correct
22 Correct 51 ms 3680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 14 ms 1252 KB Output is correct
9 Correct 25 ms 1880 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1492 KB Output is correct
12 Correct 24 ms 1904 KB Output is correct
13 Correct 20 ms 1832 KB Output is correct
14 Correct 21 ms 1792 KB Output is correct
15 Correct 66 ms 3736 KB Output is correct
16 Correct 65 ms 3784 KB Output is correct
17 Correct 47 ms 3836 KB Output is correct
18 Correct 61 ms 3628 KB Output is correct
19 Correct 68 ms 3844 KB Output is correct
20 Correct 66 ms 3892 KB Output is correct
21 Correct 49 ms 3780 KB Output is correct
22 Correct 51 ms 3680 KB Output is correct
23 Correct 68 ms 3820 KB Output is correct
24 Correct 68 ms 3876 KB Output is correct
25 Correct 50 ms 3876 KB Output is correct
26 Correct 53 ms 3640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 14 ms 1252 KB Output is correct
9 Correct 25 ms 1880 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1492 KB Output is correct
12 Correct 24 ms 1904 KB Output is correct
13 Correct 20 ms 1832 KB Output is correct
14 Correct 21 ms 1792 KB Output is correct
15 Correct 66 ms 3736 KB Output is correct
16 Correct 65 ms 3784 KB Output is correct
17 Correct 47 ms 3836 KB Output is correct
18 Correct 61 ms 3628 KB Output is correct
19 Correct 68 ms 3844 KB Output is correct
20 Correct 66 ms 3892 KB Output is correct
21 Correct 49 ms 3780 KB Output is correct
22 Correct 51 ms 3680 KB Output is correct
23 Correct 68 ms 3820 KB Output is correct
24 Correct 68 ms 3876 KB Output is correct
25 Correct 50 ms 3876 KB Output is correct
26 Correct 53 ms 3640 KB Output is correct
27 Correct 69 ms 3976 KB Output is correct
28 Correct 69 ms 4060 KB Output is correct
29 Correct 52 ms 4176 KB Output is correct
30 Correct 55 ms 3832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 14 ms 1252 KB Output is correct
9 Correct 25 ms 1880 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1492 KB Output is correct
12 Correct 24 ms 1904 KB Output is correct
13 Correct 20 ms 1832 KB Output is correct
14 Correct 21 ms 1792 KB Output is correct
15 Correct 66 ms 3736 KB Output is correct
16 Correct 65 ms 3784 KB Output is correct
17 Correct 47 ms 3836 KB Output is correct
18 Correct 61 ms 3628 KB Output is correct
19 Correct 68 ms 3844 KB Output is correct
20 Correct 66 ms 3892 KB Output is correct
21 Correct 49 ms 3780 KB Output is correct
22 Correct 51 ms 3680 KB Output is correct
23 Correct 68 ms 3820 KB Output is correct
24 Correct 68 ms 3876 KB Output is correct
25 Correct 50 ms 3876 KB Output is correct
26 Correct 53 ms 3640 KB Output is correct
27 Correct 69 ms 3976 KB Output is correct
28 Correct 69 ms 4060 KB Output is correct
29 Correct 52 ms 4176 KB Output is correct
30 Correct 55 ms 3832 KB Output is correct
31 Correct 72 ms 4024 KB Output is correct
32 Correct 70 ms 4056 KB Output is correct
33 Correct 61 ms 3964 KB Output is correct
34 Correct 55 ms 3788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 3 ms 760 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 760 KB Output is correct
7 Correct 8 ms 888 KB Output is correct
8 Correct 14 ms 1252 KB Output is correct
9 Correct 25 ms 1880 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1492 KB Output is correct
12 Correct 24 ms 1904 KB Output is correct
13 Correct 20 ms 1832 KB Output is correct
14 Correct 21 ms 1792 KB Output is correct
15 Correct 66 ms 3736 KB Output is correct
16 Correct 65 ms 3784 KB Output is correct
17 Correct 47 ms 3836 KB Output is correct
18 Correct 61 ms 3628 KB Output is correct
19 Correct 68 ms 3844 KB Output is correct
20 Correct 66 ms 3892 KB Output is correct
21 Correct 49 ms 3780 KB Output is correct
22 Correct 51 ms 3680 KB Output is correct
23 Correct 68 ms 3820 KB Output is correct
24 Correct 68 ms 3876 KB Output is correct
25 Correct 50 ms 3876 KB Output is correct
26 Correct 53 ms 3640 KB Output is correct
27 Correct 69 ms 3976 KB Output is correct
28 Correct 69 ms 4060 KB Output is correct
29 Correct 52 ms 4176 KB Output is correct
30 Correct 55 ms 3832 KB Output is correct
31 Correct 72 ms 4024 KB Output is correct
32 Correct 70 ms 4056 KB Output is correct
33 Correct 61 ms 3964 KB Output is correct
34 Correct 55 ms 3788 KB Output is correct
35 Correct 75 ms 4132 KB Output is correct
36 Correct 72 ms 4148 KB Output is correct
37 Correct 53 ms 4032 KB Output is correct
38 Correct 57 ms 4048 KB Output is correct