답안 #250164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
250164 2020-07-17T05:29:23 Z dantoh000 Minerals (JOI19_minerals) C++14
90 / 100
64 ms 3188 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, int l, int r){
    if (r == l){
        Answer(Q[l],p[0]);
        return;
    }
    else if (l + 1 == r){
        //printf("settle <%d,%d> <-> <%d,%d>\n",Q[l],Q[r],p[0],p[1]);
        //printf("last query %d\n",last);
        int q1;
        int qon, qoff, On, Off;
        if (ON[Q[l]]^ON[Q[r]]) {
            qon = ON[Q[l]]?Q[l]:Q[r];
            qoff = ON[Q[l]]?Q[r]:Q[l];
            q1 = -1;
        }
        else{
            q1 = query(Q[l]);
            qon = ON[Q[l]]?Q[l]:Q[r];
            qoff = ON[Q[l]]?Q[r]:Q[l];
        }
        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(Q[l],On);
                Answer(Q[r],Off);
            }
            else{
                Answer(Q[l],Off);
                Answer(Q[r],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
    printf("new <%d,%d>\n",l,r);
    for (auto x : p){
        printf("%d ",x);
    }
    printf("<- P\n");
    for (int i = l; i <= r; i++){
        printf("%d ",Q[i]);
    }
    printf("<- Q\n");
#endif
    //assert(p.size() == r-l+1);
    vector<int> Lp;
    vector<int> Rp;
    int n = r-l+1;
    int mid;
    mid = (l+r)/2;
    int Lon, Loff, Ron, Roff, Ls = l, Le = mid, Rs = mid+1, Re = r;
    for (int i = l; i <= mid; i++){
        Lon += ON[Q[i]];
        Loff += 1-ON[Q[i]];
    }
    for (int i = mid+1; i <= r; i++){
        Ron += ON[Q[i]];
        Roff += 1-ON[Q[i]];
    }
    if (Lon+Roff < Loff+Ron){
        swap(Ls,Rs);
        swap(Le,Re);
    }
    //printf("decided to on <%d - %d>, off <%d - %d>\n",Ls,Le,Rs,Re);
    for (int i = Ls; i <= Le; i++){
        if (!ON[Q[i]]){
            last=  query(Q[i]);
        }
    }
    for (int i = Rs; i <= Re; i++){
        if (ON[Q[i]]){
            last=  query(Q[i]);
        }
    }
    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() == Le-Ls+1 || Rp.size() == Re-Rs+1){
            //printf("ALL FILLED\n");
            for (int j = i+1; j < n; j++){
                if (Lp.size() == Le-Ls+1) 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, Ls, Le);
    solve(Rp, Rs, Re);


}
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,0,N-1);
}

Compilation message

minerals.cpp: In function 'void solve(std::vector<int>, int, int)':
minerals.cpp:140:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (Lp.size() == Le-Ls+1 || Rp.size() == Re-Rs+1){
             ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:140:47: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (Lp.size() == Le-Ls+1 || Rp.size() == Re-Rs+1){
                                     ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:143:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (Lp.size() == Le-Ls+1) Rp.push_back(p[j]);
                     ~~~~~~~~~~^~~~~~~~~~
minerals.cpp:114:12: warning: 'Roff' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (Lon+Roff < Loff+Ron){
         ~~~^~~~~
minerals.cpp:114:24: warning: 'Ron' may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (Lon+Roff < Loff+Ron){
                    ~~~~^~~~
minerals.cpp:108:14: warning: 'Loff' may be used uninitialized in this function [-Wmaybe-uninitialized]
         Loff += 1-ON[Q[i]];
         ~~~~~^~~~~~~~~~~~~
minerals.cpp:107:13: warning: 'Lon' may be used uninitialized in this function [-Wmaybe-uninitialized]
         Lon += ON[Q[i]];
         ~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 4 ms 512 KB Output is correct
4 Correct 8 ms 768 KB Output is correct
5 Correct 17 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 17 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 18 ms 1280 KB Output is correct
13 Correct 18 ms 1280 KB Output is correct
14 Correct 18 ms 1280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 17 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 18 ms 1280 KB Output is correct
13 Correct 18 ms 1280 KB Output is correct
14 Correct 18 ms 1280 KB Output is correct
15 Correct 52 ms 2868 KB Output is correct
16 Correct 56 ms 2932 KB Output is correct
17 Correct 49 ms 2816 KB Output is correct
18 Correct 52 ms 2688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 17 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 18 ms 1280 KB Output is correct
13 Correct 18 ms 1280 KB Output is correct
14 Correct 18 ms 1280 KB Output is correct
15 Correct 52 ms 2868 KB Output is correct
16 Correct 56 ms 2932 KB Output is correct
17 Correct 49 ms 2816 KB Output is correct
18 Correct 52 ms 2688 KB Output is correct
19 Correct 62 ms 3112 KB Output is correct
20 Correct 53 ms 3028 KB Output is correct
21 Correct 55 ms 2884 KB Output is correct
22 Correct 54 ms 2804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 17 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 18 ms 1280 KB Output is correct
13 Correct 18 ms 1280 KB Output is correct
14 Correct 18 ms 1280 KB Output is correct
15 Correct 52 ms 2868 KB Output is correct
16 Correct 56 ms 2932 KB Output is correct
17 Correct 49 ms 2816 KB Output is correct
18 Correct 52 ms 2688 KB Output is correct
19 Correct 62 ms 3112 KB Output is correct
20 Correct 53 ms 3028 KB Output is correct
21 Correct 55 ms 2884 KB Output is correct
22 Correct 54 ms 2804 KB Output is correct
23 Correct 53 ms 2932 KB Output is correct
24 Correct 56 ms 2948 KB Output is correct
25 Correct 53 ms 2932 KB Output is correct
26 Correct 55 ms 2820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 17 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 18 ms 1280 KB Output is correct
13 Correct 18 ms 1280 KB Output is correct
14 Correct 18 ms 1280 KB Output is correct
15 Correct 52 ms 2868 KB Output is correct
16 Correct 56 ms 2932 KB Output is correct
17 Correct 49 ms 2816 KB Output is correct
18 Correct 52 ms 2688 KB Output is correct
19 Correct 62 ms 3112 KB Output is correct
20 Correct 53 ms 3028 KB Output is correct
21 Correct 55 ms 2884 KB Output is correct
22 Correct 54 ms 2804 KB Output is correct
23 Correct 53 ms 2932 KB Output is correct
24 Correct 56 ms 2948 KB Output is correct
25 Correct 53 ms 2932 KB Output is correct
26 Correct 55 ms 2820 KB Output is correct
27 Correct 55 ms 2944 KB Output is correct
28 Correct 56 ms 2944 KB Output is correct
29 Correct 53 ms 3060 KB Output is correct
30 Correct 59 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 17 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 18 ms 1280 KB Output is correct
13 Correct 18 ms 1280 KB Output is correct
14 Correct 18 ms 1280 KB Output is correct
15 Correct 52 ms 2868 KB Output is correct
16 Correct 56 ms 2932 KB Output is correct
17 Correct 49 ms 2816 KB Output is correct
18 Correct 52 ms 2688 KB Output is correct
19 Correct 62 ms 3112 KB Output is correct
20 Correct 53 ms 3028 KB Output is correct
21 Correct 55 ms 2884 KB Output is correct
22 Correct 54 ms 2804 KB Output is correct
23 Correct 53 ms 2932 KB Output is correct
24 Correct 56 ms 2948 KB Output is correct
25 Correct 53 ms 2932 KB Output is correct
26 Correct 55 ms 2820 KB Output is correct
27 Correct 55 ms 2944 KB Output is correct
28 Correct 56 ms 2944 KB Output is correct
29 Correct 53 ms 3060 KB Output is correct
30 Correct 59 ms 2944 KB Output is correct
31 Correct 57 ms 3104 KB Output is correct
32 Correct 60 ms 3188 KB Output is correct
33 Correct 60 ms 3060 KB Output is correct
34 Correct 64 ms 2932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 4 ms 512 KB Output is correct
8 Correct 8 ms 768 KB Output is correct
9 Correct 17 ms 1280 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 12 ms 1024 KB Output is correct
12 Correct 18 ms 1280 KB Output is correct
13 Correct 18 ms 1280 KB Output is correct
14 Correct 18 ms 1280 KB Output is correct
15 Correct 52 ms 2868 KB Output is correct
16 Correct 56 ms 2932 KB Output is correct
17 Correct 49 ms 2816 KB Output is correct
18 Correct 52 ms 2688 KB Output is correct
19 Correct 62 ms 3112 KB Output is correct
20 Correct 53 ms 3028 KB Output is correct
21 Correct 55 ms 2884 KB Output is correct
22 Correct 54 ms 2804 KB Output is correct
23 Correct 53 ms 2932 KB Output is correct
24 Correct 56 ms 2948 KB Output is correct
25 Correct 53 ms 2932 KB Output is correct
26 Correct 55 ms 2820 KB Output is correct
27 Correct 55 ms 2944 KB Output is correct
28 Correct 56 ms 2944 KB Output is correct
29 Correct 53 ms 3060 KB Output is correct
30 Correct 59 ms 2944 KB Output is correct
31 Correct 57 ms 3104 KB Output is correct
32 Correct 60 ms 3188 KB Output is correct
33 Correct 60 ms 3060 KB Output is correct
34 Correct 64 ms 2932 KB Output is correct
35 Incorrect 60 ms 3160 KB Wrong Answer [2]
36 Halted 0 ms 0 KB -