Submission #167311

# Submission time Handle Problem Language Result Execution time Memory
167311 2019-12-07T09:23:47 Z ho94949 Minerals (JOI19_minerals) C++17
100 / 100
117 ms 4164 KB
//worst case: 999975 iterations

#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;
    int i = 1;
    while(V.size() != N && W.size() != N)
    {
        int plast = last;
        Q(i);
        if(last != plast) V.push_back(i);
        else W.push_back(i);
        ++i;
    }
    while(V.size() != N) V.push_back(i++);
    while(W.size() != N) W.push_back(i++);
    recur(V, W);
}

Compilation message

minerals.cpp: In function 'void Solve(int)':
minerals.cpp:92:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(V.size() != N && W.size() != N)
           ~~~~~~~~~^~~~
minerals.cpp:92:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(V.size() != N && W.size() != N)
                            ~~~~~~~~~^~~~
minerals.cpp:100:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(V.size() != N) V.push_back(i++);
           ~~~~~~~~~^~~~
minerals.cpp:101:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(W.size() != N) W.push_back(i++);
           ~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 5 ms 888 KB Output is correct
3 Correct 8 ms 1016 KB Output is correct
4 Correct 14 ms 1384 KB Output is correct
5 Correct 25 ms 1784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 14 ms 1384 KB Output is correct
9 Correct 25 ms 1784 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1528 KB Output is correct
12 Correct 25 ms 1912 KB Output is correct
13 Correct 20 ms 1872 KB Output is correct
14 Correct 21 ms 1808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 14 ms 1384 KB Output is correct
9 Correct 25 ms 1784 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1528 KB Output is correct
12 Correct 25 ms 1912 KB Output is correct
13 Correct 20 ms 1872 KB Output is correct
14 Correct 21 ms 1808 KB Output is correct
15 Correct 66 ms 3700 KB Output is correct
16 Correct 64 ms 3900 KB Output is correct
17 Correct 80 ms 3792 KB Output is correct
18 Correct 50 ms 3516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 14 ms 1384 KB Output is correct
9 Correct 25 ms 1784 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1528 KB Output is correct
12 Correct 25 ms 1912 KB Output is correct
13 Correct 20 ms 1872 KB Output is correct
14 Correct 21 ms 1808 KB Output is correct
15 Correct 66 ms 3700 KB Output is correct
16 Correct 64 ms 3900 KB Output is correct
17 Correct 80 ms 3792 KB Output is correct
18 Correct 50 ms 3516 KB Output is correct
19 Correct 65 ms 3780 KB Output is correct
20 Correct 66 ms 3860 KB Output is correct
21 Correct 49 ms 3820 KB Output is correct
22 Correct 51 ms 3776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 14 ms 1384 KB Output is correct
9 Correct 25 ms 1784 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1528 KB Output is correct
12 Correct 25 ms 1912 KB Output is correct
13 Correct 20 ms 1872 KB Output is correct
14 Correct 21 ms 1808 KB Output is correct
15 Correct 66 ms 3700 KB Output is correct
16 Correct 64 ms 3900 KB Output is correct
17 Correct 80 ms 3792 KB Output is correct
18 Correct 50 ms 3516 KB Output is correct
19 Correct 65 ms 3780 KB Output is correct
20 Correct 66 ms 3860 KB Output is correct
21 Correct 49 ms 3820 KB Output is correct
22 Correct 51 ms 3776 KB Output is correct
23 Correct 69 ms 3984 KB Output is correct
24 Correct 68 ms 3836 KB Output is correct
25 Correct 50 ms 3984 KB Output is correct
26 Correct 52 ms 3644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 14 ms 1384 KB Output is correct
9 Correct 25 ms 1784 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1528 KB Output is correct
12 Correct 25 ms 1912 KB Output is correct
13 Correct 20 ms 1872 KB Output is correct
14 Correct 21 ms 1808 KB Output is correct
15 Correct 66 ms 3700 KB Output is correct
16 Correct 64 ms 3900 KB Output is correct
17 Correct 80 ms 3792 KB Output is correct
18 Correct 50 ms 3516 KB Output is correct
19 Correct 65 ms 3780 KB Output is correct
20 Correct 66 ms 3860 KB Output is correct
21 Correct 49 ms 3820 KB Output is correct
22 Correct 51 ms 3776 KB Output is correct
23 Correct 69 ms 3984 KB Output is correct
24 Correct 68 ms 3836 KB Output is correct
25 Correct 50 ms 3984 KB Output is correct
26 Correct 52 ms 3644 KB Output is correct
27 Correct 68 ms 3968 KB Output is correct
28 Correct 69 ms 3980 KB Output is correct
29 Correct 51 ms 4056 KB Output is correct
30 Correct 53 ms 3728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 14 ms 1384 KB Output is correct
9 Correct 25 ms 1784 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1528 KB Output is correct
12 Correct 25 ms 1912 KB Output is correct
13 Correct 20 ms 1872 KB Output is correct
14 Correct 21 ms 1808 KB Output is correct
15 Correct 66 ms 3700 KB Output is correct
16 Correct 64 ms 3900 KB Output is correct
17 Correct 80 ms 3792 KB Output is correct
18 Correct 50 ms 3516 KB Output is correct
19 Correct 65 ms 3780 KB Output is correct
20 Correct 66 ms 3860 KB Output is correct
21 Correct 49 ms 3820 KB Output is correct
22 Correct 51 ms 3776 KB Output is correct
23 Correct 69 ms 3984 KB Output is correct
24 Correct 68 ms 3836 KB Output is correct
25 Correct 50 ms 3984 KB Output is correct
26 Correct 52 ms 3644 KB Output is correct
27 Correct 68 ms 3968 KB Output is correct
28 Correct 69 ms 3980 KB Output is correct
29 Correct 51 ms 4056 KB Output is correct
30 Correct 53 ms 3728 KB Output is correct
31 Correct 72 ms 4164 KB Output is correct
32 Correct 71 ms 4028 KB Output is correct
33 Correct 53 ms 3968 KB Output is correct
34 Correct 69 ms 3920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 632 KB Output is correct
2 Correct 2 ms 632 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 2 ms 632 KB Output is correct
5 Correct 4 ms 760 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 8 ms 1016 KB Output is correct
8 Correct 14 ms 1384 KB Output is correct
9 Correct 25 ms 1784 KB Output is correct
10 Correct 4 ms 760 KB Output is correct
11 Correct 17 ms 1528 KB Output is correct
12 Correct 25 ms 1912 KB Output is correct
13 Correct 20 ms 1872 KB Output is correct
14 Correct 21 ms 1808 KB Output is correct
15 Correct 66 ms 3700 KB Output is correct
16 Correct 64 ms 3900 KB Output is correct
17 Correct 80 ms 3792 KB Output is correct
18 Correct 50 ms 3516 KB Output is correct
19 Correct 65 ms 3780 KB Output is correct
20 Correct 66 ms 3860 KB Output is correct
21 Correct 49 ms 3820 KB Output is correct
22 Correct 51 ms 3776 KB Output is correct
23 Correct 69 ms 3984 KB Output is correct
24 Correct 68 ms 3836 KB Output is correct
25 Correct 50 ms 3984 KB Output is correct
26 Correct 52 ms 3644 KB Output is correct
27 Correct 68 ms 3968 KB Output is correct
28 Correct 69 ms 3980 KB Output is correct
29 Correct 51 ms 4056 KB Output is correct
30 Correct 53 ms 3728 KB Output is correct
31 Correct 72 ms 4164 KB Output is correct
32 Correct 71 ms 4028 KB Output is correct
33 Correct 53 ms 3968 KB Output is correct
34 Correct 69 ms 3920 KB Output is correct
35 Correct 74 ms 4140 KB Output is correct
36 Correct 81 ms 4092 KB Output is correct
37 Correct 53 ms 4104 KB Output is correct
38 Correct 117 ms 4092 KB Output is correct