답안 #973160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
973160 2024-05-01T14:53:44 Z the_coding_pooh Minerals (JOI19_minerals) C++14
100 / 100
42 ms 4516 KB
#include <bits/stdc++.h>
using namespace std;

// #define __LOCAL__

#ifdef __LOCAL__
void Solve(int N);

const int SIZE = 1e3 + 5;

int type[SIZE], cnt[SIZE], in_cnt[SIZE];

int ttl = 0, qcnt = 0;

int Query(int i){
    qcnt++;
    if(!cnt[type[i]])
        ttl++;
    if(in_cnt[i]){
        cnt[type[i]]--;
        in_cnt[i] = 0;
    }
    else if(!in_cnt[i]){
        cnt[type[i]]++;
        in_cnt[i] = 1;
    }
    if(!cnt[type[i]])
        ttl--;

    return ttl;
}

void Answer(int a, int b){
    if(type[a] != type[b])
        cout << a << ' ' << b << " WA\n";
}

int main(){
    int n;
    cin >> n;
    for (int i = 1, a, b; i <= n;i++){
        cin >> a >> b;
        type[a] = i;
        type[b] = i;
    }
    Solve(n);
    cout << qcnt << '\n';

}
#endif
#ifndef __LOCAL__
#include "minerals.h"
#endif

#define uwu return;

const double magic = exp(-1);

void solve(vector<int> A, vector<int> B, bool b){
    if(A.empty())
        uwu
    if(A.size() == 1){
        Answer(A[0], B[0]);
        uwu
    }
    
    int m = max((int) (b * A.size() + (1 - b * 2) * magic * A.size()), 1);

    vector<int> recA[2], recB[2];

    for (int i = 0; i < A.size(); i++){
        recA[i >= m].push_back(A[i]);
    }

    int prev;

    for(auto i : recA[b]){
        prev = Query(i);
    }

    for(auto i : B){
        if(recA[0].size() == recB[0].size()){
            recB[1].push_back(i);
        }
        else if(recA[1].size() == recB[1].size()){
            recB[0].push_back(i);
        }
        else{
            int now = Query(i);
            now == prev ? recB[0].push_back(i) : recB[1].push_back(i);
            prev = now;
        }
    }

    solve(recA[0], recB[0], 1), solve(recA[1], recB[1], 0);
    return;
}

void Solve(int N){
    vector<int> veca, vecb;

    for (int i = 1, pre = 0, tmp = 0; i <= 2 * N; i++){
        tmp = Query(i);
        if(tmp == pre)
            veca.push_back(i);
        else
            vecb.push_back(i);
        pre = tmp;
    }

    random_shuffle(veca.begin(), veca.end());
    random_shuffle(vecb.begin(), vecb.end());

    solve(veca, vecb, 1);
    uwu
}

Compilation message

minerals.cpp: In function 'void solve(std::vector<int>, std::vector<int>, bool)':
minerals.cpp:71:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i = 0; i < A.size(); i++){
      |                     ~~^~~~~~~~~~
minerals.cpp:90:25: warning: 'prev' may be used uninitialized in this function [-Wmaybe-uninitialized]
   90 |             now == prev ? recB[0].push_back(i) : recB[1].push_back(i);
      |             ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 6 ms 1132 KB Output is correct
5 Correct 12 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 1132 KB Output is correct
9 Correct 12 ms 1624 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 13 ms 1824 KB Output is correct
13 Correct 12 ms 1788 KB Output is correct
14 Correct 11 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 1132 KB Output is correct
9 Correct 12 ms 1624 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 13 ms 1824 KB Output is correct
13 Correct 12 ms 1788 KB Output is correct
14 Correct 11 ms 1784 KB Output is correct
15 Correct 32 ms 3796 KB Output is correct
16 Correct 32 ms 3736 KB Output is correct
17 Correct 40 ms 4328 KB Output is correct
18 Correct 31 ms 4080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 1132 KB Output is correct
9 Correct 12 ms 1624 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 13 ms 1824 KB Output is correct
13 Correct 12 ms 1788 KB Output is correct
14 Correct 11 ms 1784 KB Output is correct
15 Correct 32 ms 3796 KB Output is correct
16 Correct 32 ms 3736 KB Output is correct
17 Correct 40 ms 4328 KB Output is correct
18 Correct 31 ms 4080 KB Output is correct
19 Correct 34 ms 3740 KB Output is correct
20 Correct 36 ms 3796 KB Output is correct
21 Correct 33 ms 4052 KB Output is correct
22 Correct 32 ms 3692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 1132 KB Output is correct
9 Correct 12 ms 1624 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 13 ms 1824 KB Output is correct
13 Correct 12 ms 1788 KB Output is correct
14 Correct 11 ms 1784 KB Output is correct
15 Correct 32 ms 3796 KB Output is correct
16 Correct 32 ms 3736 KB Output is correct
17 Correct 40 ms 4328 KB Output is correct
18 Correct 31 ms 4080 KB Output is correct
19 Correct 34 ms 3740 KB Output is correct
20 Correct 36 ms 3796 KB Output is correct
21 Correct 33 ms 4052 KB Output is correct
22 Correct 32 ms 3692 KB Output is correct
23 Correct 35 ms 3728 KB Output is correct
24 Correct 36 ms 3800 KB Output is correct
25 Correct 38 ms 4308 KB Output is correct
26 Correct 33 ms 4044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 1132 KB Output is correct
9 Correct 12 ms 1624 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 13 ms 1824 KB Output is correct
13 Correct 12 ms 1788 KB Output is correct
14 Correct 11 ms 1784 KB Output is correct
15 Correct 32 ms 3796 KB Output is correct
16 Correct 32 ms 3736 KB Output is correct
17 Correct 40 ms 4328 KB Output is correct
18 Correct 31 ms 4080 KB Output is correct
19 Correct 34 ms 3740 KB Output is correct
20 Correct 36 ms 3796 KB Output is correct
21 Correct 33 ms 4052 KB Output is correct
22 Correct 32 ms 3692 KB Output is correct
23 Correct 35 ms 3728 KB Output is correct
24 Correct 36 ms 3800 KB Output is correct
25 Correct 38 ms 4308 KB Output is correct
26 Correct 33 ms 4044 KB Output is correct
27 Correct 34 ms 3880 KB Output is correct
28 Correct 34 ms 3832 KB Output is correct
29 Correct 34 ms 4428 KB Output is correct
30 Correct 38 ms 4516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 1132 KB Output is correct
9 Correct 12 ms 1624 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 13 ms 1824 KB Output is correct
13 Correct 12 ms 1788 KB Output is correct
14 Correct 11 ms 1784 KB Output is correct
15 Correct 32 ms 3796 KB Output is correct
16 Correct 32 ms 3736 KB Output is correct
17 Correct 40 ms 4328 KB Output is correct
18 Correct 31 ms 4080 KB Output is correct
19 Correct 34 ms 3740 KB Output is correct
20 Correct 36 ms 3796 KB Output is correct
21 Correct 33 ms 4052 KB Output is correct
22 Correct 32 ms 3692 KB Output is correct
23 Correct 35 ms 3728 KB Output is correct
24 Correct 36 ms 3800 KB Output is correct
25 Correct 38 ms 4308 KB Output is correct
26 Correct 33 ms 4044 KB Output is correct
27 Correct 34 ms 3880 KB Output is correct
28 Correct 34 ms 3832 KB Output is correct
29 Correct 34 ms 4428 KB Output is correct
30 Correct 38 ms 4516 KB Output is correct
31 Correct 35 ms 4096 KB Output is correct
32 Correct 36 ms 4096 KB Output is correct
33 Correct 34 ms 4080 KB Output is correct
34 Correct 35 ms 4184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 3 ms 600 KB Output is correct
8 Correct 6 ms 1132 KB Output is correct
9 Correct 12 ms 1624 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 10 ms 1112 KB Output is correct
12 Correct 13 ms 1824 KB Output is correct
13 Correct 12 ms 1788 KB Output is correct
14 Correct 11 ms 1784 KB Output is correct
15 Correct 32 ms 3796 KB Output is correct
16 Correct 32 ms 3736 KB Output is correct
17 Correct 40 ms 4328 KB Output is correct
18 Correct 31 ms 4080 KB Output is correct
19 Correct 34 ms 3740 KB Output is correct
20 Correct 36 ms 3796 KB Output is correct
21 Correct 33 ms 4052 KB Output is correct
22 Correct 32 ms 3692 KB Output is correct
23 Correct 35 ms 3728 KB Output is correct
24 Correct 36 ms 3800 KB Output is correct
25 Correct 38 ms 4308 KB Output is correct
26 Correct 33 ms 4044 KB Output is correct
27 Correct 34 ms 3880 KB Output is correct
28 Correct 34 ms 3832 KB Output is correct
29 Correct 34 ms 4428 KB Output is correct
30 Correct 38 ms 4516 KB Output is correct
31 Correct 35 ms 4096 KB Output is correct
32 Correct 36 ms 4096 KB Output is correct
33 Correct 34 ms 4080 KB Output is correct
34 Correct 35 ms 4184 KB Output is correct
35 Correct 39 ms 4200 KB Output is correct
36 Correct 42 ms 4096 KB Output is correct
37 Correct 35 ms 4048 KB Output is correct
38 Correct 36 ms 3944 KB Output is correct