Submission #120680

# Submission time Handle Problem Language Result Execution time Memory
120680 2019-06-25T08:02:34 Z 이온조(#2959) Minerals (JOI19_minerals) C++14
0 / 100
3 ms 384 KB
#include "minerals.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

bool chk[100009];

int query(int x) {
    chk[x] = !chk[x];
    //printf("query x: %d\n", x);
    return Query(x);
}

void answer(int a, int b) {
    //printf("answer: (%d, %d)\n", a, b);
    Answer(a, b);
}

pair<vi, vi> split(int N) {
    vector<int> A, B;
    int pr = 0;
    for(int i=1; i<=2*N; i++) {
        int Q = query(i);
        if(pr != Q) A.push_back(i);
        else B.push_back(i);
        pr = Q;
    }
    return {A, B};
}

void go(vector<int> &A, vector<int> &B, bool AC, bool BC) {
    //puts("AB");
    //for(auto& it: A) printf("%d ",it); puts("");
    //for(auto& it: B) printf("%d ",it); puts("");
    int N = A.size();
    if(N == 1) {
        answer(A[0], B[0]);
        return;
    }
    if(N == 2) {
        int X = query(A[0]);
        int Y = query(B[0]);
        if(!AC && !BC && X != Y) swap(A[0], A[1]);
        if(!AC && BC && X == Y) swap(A[0], A[1]);
        if(AC && !BC && X == Y) swap(A[0], A[1]);
        if(AC && BC && X != Y) swap(A[0], A[1]);
        answer(A[0], B[0]);
        answer(A[1], B[1]);
        return;
    }
    if(!AC) {
        int m = N/2, pr;
        vector<int> LA, RA, LB, RB;
        for(int i=0; i<m; i++) {
            pr = query(A[i]);
            LA.push_back(A[i]);
        }
        for(int i=m; i<N; i++) RA.push_back(A[i]);
        for(int i=0; i<N; i++) {
            int Q = query(B[i]);
            if(pr != Q) RB.push_back(B[i]);
            else LB.push_back(B[i]);
            pr = Q;
        }
        go(LA, LB, 1, !BC);
        go(RA, RB, 0, !BC);
    }
    if(AC) {
        int m = N/2, pr;
        vector<int> LA, RA, LB, RB;
        for(int i=0; i<m; i++) {
            pr = query(A[i]);
            LA.push_back(A[i]);
        }
        for(int i=m; i<N; i++) RA.push_back(A[i]);
        for(int i=0; i<N; i++) {
            int Q = query(B[i]);
            if(pr != Q) LB.push_back(B[i]);
            else RB.push_back(B[i]);
            pr = Q;
        }
        go(LA, LB, 0, !BC);
        go(RA, RB, 1, !BC);
    }
}

void Solve(int N) {
    vi A, B; tie(A, B) = split(N);
    go(A, B, 1, 1);
}

Compilation message

minerals.cpp: In function 'void go(std::vector<int>&, std::vector<int>&, bool, bool)':
minerals.cpp:78:13: warning: 'pr' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if(pr != Q) LB.push_back(B[i]);
             ^~
minerals.cpp:61:13: warning: 'pr' may be used uninitialized in this function [-Wmaybe-uninitialized]
             if(pr != Q) RB.push_back(B[i]);
             ^~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB Output is correct
2 Incorrect 3 ms 384 KB Wrong Answer [5]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Wrong Answer [5]
2 Halted 0 ms 0 KB -