답안 #250179

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250179 2020-07-17T05:56:05 Z dantoh000 Minerals (JOI19_minerals) C++14
90 / 100
81 ms 3924 KB
#include <bits/stdc++.h>
#include "minerals.h"
using namespace std;
vector<int> Q;
vector<int> P;
int ans[86005];
int ON[86005];
int last;
int verdict;
int query(int x){
    ON[x] ^= 1;
    verdict = ON[x];
    return Query(x);
}
void solve(vector<int> p, vector<int> q){
    if (p.size() == 1){
        Answer(q[0],p[0]);
        return;
    }
    /*else if (p.size() == 2){
        printf("settle <%d,%d> <-> <%d,%d>\n",q[0],q[1],p[0],p[1]);
        //printf("last query %d\n",last);
        int q1;
        int qon, qoff, On, Off;
        if (ON[q[0]]^ON[q[1]]) {
            qon = ON[q[0]]?q[0]:q[1];
            qoff = ON[q[0]]?q[1]:q[0];
            q1 = -1;
        }
        else{
            q1 = query(q[0]);
            qon = ON[q[0]]?q[0]:q[1];
            qoff = ON[q[0]]?q[1]:q[0];
        }
        assert(ON[qon] && !ON[qoff]);
        if (ON[p[0]] ^ ON[p[1]]){
            On = ON[p[0]]?p[0]:p[1];
            Off = ON[p[0]]?p[1]:p[0];
            if (q1 == -1){
                q1 = query(On);
                if (q1 == last){
                    Answer(qon, On);
                    Answer(qoff, Off);
                }
            }
            else if (q1 == last){
                Answer(qon,On);
                Answer(qoff,Off);
            }
            else{
                Answer(qon,Off);
                Answer(qoff,On);
            }
            last = q1;
            return;
        }
        if (q1 == -1){
            q1 = query(p[0]);
            On = ON[p[0]]?p[0]:p[1];
            Off = ON[p[0]]?p[1]:p[0];
            if ((verdict == 0) ^ (q1 == last)){
                Answer(qon,On);
                Answer(qoff,Off);
            }
            else{
                Answer(qoff,On);
                Answer(qon,Off);
            }
            last = q1;
            return;
        }
        else last = q1;
        q1 = query(p[0]);
        On = ON[p[0]]?p[0]:p[1];
        Off = ON[p[0]]?p[1]:p[0];
        if ((verdict == 0) ^ (q1 == last)){
            Answer(qon,On);
            Answer(qoff,Off);
        }
        else{
            Answer(qoff,On);
            Answer(qon,Off);
        }
        last = q1;
        return;
    }*/
#ifdef debug
    for (auto x : p){
        printf("%d ",x);
    }
    printf("<- P\n");
    for (auto x : q){
        printf("%d ",x);
    }
    printf("<- P\n");
#endif
    assert(p.size() == q.size());
    vector<int> Lp;
    vector<int> Rp;
    vector<int> Lq, Rq;
    int n = q.size();
    int mid = n/2;
    for (auto x : q){
        if (ON[x]){
            if (Lq.size() == mid){
                last = query(x);
                Rq.push_back(x);
            }
            else{
                Lq.push_back(x);
            }
        }
        else{
            if (Rq.size() == q.size()-mid){
                last = query(x);
                Lq.push_back(x);
            }
            else{
                Rq.push_back(x);
            }
        }
    }
    for (int i = 0; i < n; i++){
        int q = query(p[i]);
        if (q == last){
            //printf("%d goes left\n",p[i]);
            Lp.push_back(p[i]);
        }
        else{
            //printf("%d goes right\n",p[i]);
            Rp.push_back(p[i]);
        }
        last = q;
        if (Lp.size() == Lq.size() || Rp.size() == Rq.size()){
            //printf("ALL FILLED\n");
            for (int j = i+1; j < n; j++){
                if (Lp.size() == Lq.size()) Rp.push_back(p[j]);
                else Lp.push_back(p[j]);
            }
            break;
        }

    }
#ifdef debug
    printf("Lp: ");
    for (auto x : Lp) printf("%d ",x);
    printf("\n");
    printf("Rp: ");
    for (auto x : Rp) printf("%d ",x);
    printf("\n");
#endif

    solve(Lp, Lq);
    solve(Rp, Rq);


}
void Solve(int N) {
    for (int i = 1; i <= 2*N; i++){
        int q = query(i);
        if (q == last){
            Q.push_back(i);
        }
        else{
            P.push_back(i);
        }
        last = q;
        ON[i] = 1;
    }
    srand(time(NULL));
    random_shuffle(Q.begin(),Q.end());
    random_shuffle(P.begin(),P.end());
    solve(P,Q);
}

Compilation message

minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>)':
minerals.cpp:105:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (Lq.size() == mid){
                 ~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 4 ms 512 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 12 ms 896 KB Output is correct
5 Correct 23 ms 1536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 23 ms 1536 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 1152 KB Output is correct
12 Correct 24 ms 1536 KB Output is correct
13 Correct 23 ms 1604 KB Output is correct
14 Correct 23 ms 1664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 23 ms 1536 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 1152 KB Output is correct
12 Correct 24 ms 1536 KB Output is correct
13 Correct 23 ms 1604 KB Output is correct
14 Correct 23 ms 1664 KB Output is correct
15 Correct 72 ms 3520 KB Output is correct
16 Correct 72 ms 3700 KB Output is correct
17 Correct 64 ms 3524 KB Output is correct
18 Correct 66 ms 3516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 23 ms 1536 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 1152 KB Output is correct
12 Correct 24 ms 1536 KB Output is correct
13 Correct 23 ms 1604 KB Output is correct
14 Correct 23 ms 1664 KB Output is correct
15 Correct 72 ms 3520 KB Output is correct
16 Correct 72 ms 3700 KB Output is correct
17 Correct 64 ms 3524 KB Output is correct
18 Correct 66 ms 3516 KB Output is correct
19 Correct 72 ms 3764 KB Output is correct
20 Correct 71 ms 3572 KB Output is correct
21 Correct 68 ms 3576 KB Output is correct
22 Correct 68 ms 3424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 23 ms 1536 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 1152 KB Output is correct
12 Correct 24 ms 1536 KB Output is correct
13 Correct 23 ms 1604 KB Output is correct
14 Correct 23 ms 1664 KB Output is correct
15 Correct 72 ms 3520 KB Output is correct
16 Correct 72 ms 3700 KB Output is correct
17 Correct 64 ms 3524 KB Output is correct
18 Correct 66 ms 3516 KB Output is correct
19 Correct 72 ms 3764 KB Output is correct
20 Correct 71 ms 3572 KB Output is correct
21 Correct 68 ms 3576 KB Output is correct
22 Correct 68 ms 3424 KB Output is correct
23 Correct 72 ms 3708 KB Output is correct
24 Correct 74 ms 3684 KB Output is correct
25 Correct 69 ms 3704 KB Output is correct
26 Correct 71 ms 3552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 23 ms 1536 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 1152 KB Output is correct
12 Correct 24 ms 1536 KB Output is correct
13 Correct 23 ms 1604 KB Output is correct
14 Correct 23 ms 1664 KB Output is correct
15 Correct 72 ms 3520 KB Output is correct
16 Correct 72 ms 3700 KB Output is correct
17 Correct 64 ms 3524 KB Output is correct
18 Correct 66 ms 3516 KB Output is correct
19 Correct 72 ms 3764 KB Output is correct
20 Correct 71 ms 3572 KB Output is correct
21 Correct 68 ms 3576 KB Output is correct
22 Correct 68 ms 3424 KB Output is correct
23 Correct 72 ms 3708 KB Output is correct
24 Correct 74 ms 3684 KB Output is correct
25 Correct 69 ms 3704 KB Output is correct
26 Correct 71 ms 3552 KB Output is correct
27 Correct 81 ms 3796 KB Output is correct
28 Correct 74 ms 3772 KB Output is correct
29 Correct 78 ms 3744 KB Output is correct
30 Correct 70 ms 3572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 23 ms 1536 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 1152 KB Output is correct
12 Correct 24 ms 1536 KB Output is correct
13 Correct 23 ms 1604 KB Output is correct
14 Correct 23 ms 1664 KB Output is correct
15 Correct 72 ms 3520 KB Output is correct
16 Correct 72 ms 3700 KB Output is correct
17 Correct 64 ms 3524 KB Output is correct
18 Correct 66 ms 3516 KB Output is correct
19 Correct 72 ms 3764 KB Output is correct
20 Correct 71 ms 3572 KB Output is correct
21 Correct 68 ms 3576 KB Output is correct
22 Correct 68 ms 3424 KB Output is correct
23 Correct 72 ms 3708 KB Output is correct
24 Correct 74 ms 3684 KB Output is correct
25 Correct 69 ms 3704 KB Output is correct
26 Correct 71 ms 3552 KB Output is correct
27 Correct 81 ms 3796 KB Output is correct
28 Correct 74 ms 3772 KB Output is correct
29 Correct 78 ms 3744 KB Output is correct
30 Correct 70 ms 3572 KB Output is correct
31 Correct 80 ms 3840 KB Output is correct
32 Correct 81 ms 3924 KB Output is correct
33 Correct 74 ms 3748 KB Output is correct
34 Correct 80 ms 3688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 4 ms 512 KB Output is correct
7 Correct 6 ms 640 KB Output is correct
8 Correct 12 ms 896 KB Output is correct
9 Correct 23 ms 1536 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 1152 KB Output is correct
12 Correct 24 ms 1536 KB Output is correct
13 Correct 23 ms 1604 KB Output is correct
14 Correct 23 ms 1664 KB Output is correct
15 Correct 72 ms 3520 KB Output is correct
16 Correct 72 ms 3700 KB Output is correct
17 Correct 64 ms 3524 KB Output is correct
18 Correct 66 ms 3516 KB Output is correct
19 Correct 72 ms 3764 KB Output is correct
20 Correct 71 ms 3572 KB Output is correct
21 Correct 68 ms 3576 KB Output is correct
22 Correct 68 ms 3424 KB Output is correct
23 Correct 72 ms 3708 KB Output is correct
24 Correct 74 ms 3684 KB Output is correct
25 Correct 69 ms 3704 KB Output is correct
26 Correct 71 ms 3552 KB Output is correct
27 Correct 81 ms 3796 KB Output is correct
28 Correct 74 ms 3772 KB Output is correct
29 Correct 78 ms 3744 KB Output is correct
30 Correct 70 ms 3572 KB Output is correct
31 Correct 80 ms 3840 KB Output is correct
32 Correct 81 ms 3924 KB Output is correct
33 Correct 74 ms 3748 KB Output is correct
34 Correct 80 ms 3688 KB Output is correct
35 Incorrect 81 ms 3848 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -