답안 #978019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
978019 2024-05-08T16:34:09 Z salmon 코알라 (APIO17_koala) C++14
76 / 100
74 ms 720 KB
#include <bits/stdc++.h>
#include "koala.h"
using namespace std;

int minValue(int N, int W) {
    int res[N];
    int in[N];

    for(int i = 0; i < N; i++){
        in[i] = 0;
    }
    in[0] = 1;

    playRound(in,res);

    int p = -1;
    for(int i = 0; i < N; i++){
        if(res[i] <= in[i]){
            p = i;
        }
    }

    return p;
}

int maxValue(int N, int W) {
    set<int> sat;
    int res[N];
    int in[N];

    for(int i = 0; i < N; i++){
        sat.insert(i);
        in[i] = 0;
    }

    while(sat.size() != 1){
        int num = 100 / sat.size();

        for(int i = 0; i < N; i++){
            in[i] = 0;
        }

        for(int i : sat){
            in[i] = num;
        }

        playRound(in,res);

        for(int i = 0; i < N; i++){
            if(res[i] <= in[i] && sat.find(i) != sat.end()){
                sat.erase(i);
            }
        }
    }



    for(int i : sat) return i;
}

//9 5 3
int greaterValue(int N, int W) {
    int in[N];
    int res[N];

    int it = minValue(N, W);

    if(it == 0) return 1;
    if(it == 1) return 0;

    for(int i = 0; i < N; i++){
        in[i] = 0;
    }

    in[0] = 4;
    in[1] = 4;

    playRound(in,res);

    if(res[0] > in[0] && res[1] <= in[1]) return 0;
    if(res[1] > in[1] && res[0] <= in[0]) return 1;

    if(res[0] > in[0]){
        in[0] = 8;
        in[1] = 8;
    }
    else{
        in[0] = 2;
        in[1] = 2;
    }

    playRound(in,res);

    if(res[0] > in[0] && res[1] <= in[1]) return 0;
    if(res[1] > in[1] && res[0] <= in[0]) return 1;

    in[0] = 2;
    in[1] = 2;
}

bool b(int a, int b){
    if(b == -1) return true;
    if(a == -1) return false;

    int in[100];
    int res[100];

    for(int i = 0; i < 100; i++){
        in[i] = 0;
    }

    in[a] = 100;
    in[b] = 100;

    playRound(in,res);

    return in[b] < res[b];
}

bool c(int a, int b){
    if(b == -1) return true;
    if(a == -1) return false;

    int in[100];
    int res[100];

    for(int i = 0; i < 100; i++){
        in[i] = 0;
    }

    in[a] = 4;
    in[b] = 4;

    playRound(in,res);

    if(res[a] > in[a] && res[b] <= in[b]) return false;
    if(res[b] > in[b] && res[a] <= in[a]) return true;

    if(res[a] > in[a]){
        in[a] = 8;
        in[b] = 8;
    }
    else{
        in[a] = 2;
        in[b] = 2;
    }

    playRound(in,res);

    if(res[a] > in[a] && res[b] <= in[b]) return false;
    if(res[b] > in[b] && res[a] <= in[a]) return true;
}

vector<int> sblort(vector<int> input){

    queue<vector<int>> q;

    for(int i : input){
        q.push({i,-1});
    }

    while(q.size() != 1){
        vector<int> v1 = q.front();
        q.pop();
        vector<int> v2 = q.front();
        q.pop();

        vector<int> v3;

        int it1 = 0;
        int it2 = 0;
        for(int i = 0; i < v1.size() + v2.size() - 1; i++){
            if(c(v1[it1],v2[it2])){
                v3.push_back(v1[it1]);
                it1++;
            }
            else{
                v3.push_back(v2[it2]);
                it2++;
            }
        }

        q.push(v3);
    }

    q.front().pop_back();

    return q.front();
}

void allValues(int N, int W, int *P) {
    if (W == 2*N) {
        queue<vector<int>> q;
        vector<int> v;

        for(int i = 0; i < N; i++){
            vector<int> temp = {i,-1};
            q.push(temp);
        }

        while(q.size() != 1){
            vector<int> v1,v2,v3;

            v1 = q.front();
            q.pop();
            v2 = q.front();
            q.pop();

            int it1,it2;
            it1 = 0;
            it2 = 0;

            for(int i = 0; i < v1.size() + v2.size() - 1; i++){
                if(b(v1[it1],v2[it2])){
                    v3.push_back(v1[it1]);
                    it1++;
                }
                else{
                    v3.push_back(v2[it2]);
                    it2++;
                }
            }

            q.push(v3);
        }

        v = q.front();

        for(int i = 0; i < N; i++){
            P[v[i]] = i + 1;
        }

    }
    else{
        int in[100];
        int res[100];

        vector<int> input;
        vector<int> order;
        int l = minValue(N,W);

        P[l] = 1;

        for(int i = 0; i < 100; i++){
            in[i] = 1;
        }

        playRound(in,res);

        for(int i = 0; i < N; i++){
            if(res[i] <= in[i] && i != l){
                input.push_back(i);
            }
        }

        vector<int> v = sblort(input);
        input.clear();

        for(int i : v){
            order.push_back(i);
        }

        for(int i = 0; i < N; i++){
            if(res[i] > in[i]){
                input.push_back(i);
            }
        }

        v = sblort(input);
        input.clear();

        for(int i : v){
            order.push_back(i);
        }

        for(int i = 0; i < N - 1; i++){
            P[order[i]] = i + 2;
        }
    }
}

Compilation message

koala.cpp: In function 'std::vector<int> sblort(std::vector<int>)':
koala.cpp:172:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  172 |         for(int i = 0; i < v1.size() + v2.size() - 1; i++){
      |                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp: In function 'void allValues(int, int, int*)':
koala.cpp:213:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  213 |             for(int i = 0; i < v1.size() + v2.size() - 1; i++){
      |                            ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:27:14: warning: control reaches end of non-void function [-Wreturn-type]
   27 |     set<int> sat;
      |              ^~~
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:98:11: warning: control reaches end of non-void function [-Wreturn-type]
   98 |     in[1] = 2;
      |     ~~~~~~^~~
koala.cpp: In function 'bool c(int, int)':
koala.cpp:152:1: warning: control reaches end of non-void function [-Wreturn-type]
  152 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 5 ms 344 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 344 KB Output is correct
2 Correct 12 ms 460 KB Output is correct
3 Correct 11 ms 344 KB Output is correct
4 Correct 11 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 460 KB Output is correct
2 Correct 64 ms 464 KB Output is correct
3 Correct 69 ms 460 KB Output is correct
4 Correct 71 ms 464 KB Output is correct
5 Correct 73 ms 720 KB Output is correct
6 Correct 67 ms 464 KB Output is correct
7 Correct 74 ms 704 KB Output is correct
8 Correct 67 ms 472 KB Output is correct
9 Correct 67 ms 596 KB Output is correct
10 Correct 66 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 456 KB Output is correct
2 Correct 26 ms 344 KB Output is correct
3 Correct 26 ms 456 KB Output is correct
4 Correct 25 ms 344 KB Output is correct
5 Correct 25 ms 344 KB Output is correct
6 Correct 25 ms 344 KB Output is correct
7 Correct 24 ms 344 KB Output is correct
8 Correct 25 ms 344 KB Output is correct
9 Correct 24 ms 344 KB Output is correct
10 Correct 24 ms 344 KB Output is correct
11 Correct 25 ms 344 KB Output is correct
12 Correct 18 ms 456 KB Output is correct
13 Correct 25 ms 456 KB Output is correct
14 Correct 23 ms 344 KB Output is correct
15 Correct 23 ms 344 KB Output is correct
16 Correct 22 ms 456 KB Output is correct
17 Correct 22 ms 600 KB Output is correct
18 Correct 23 ms 428 KB Output is correct
19 Correct 23 ms 344 KB Output is correct
20 Correct 23 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 13 ms 344 KB Output is partially correct
2 Partially correct 17 ms 456 KB Output is partially correct
3 Partially correct 17 ms 344 KB Output is partially correct
4 Partially correct 17 ms 344 KB Output is partially correct
5 Partially correct 16 ms 456 KB Output is partially correct
6 Partially correct 16 ms 344 KB Output is partially correct
7 Partially correct 17 ms 344 KB Output is partially correct
8 Partially correct 17 ms 344 KB Output is partially correct
9 Partially correct 17 ms 344 KB Output is partially correct
10 Partially correct 16 ms 344 KB Output is partially correct
11 Partially correct 17 ms 344 KB Output is partially correct
12 Partially correct 12 ms 344 KB Output is partially correct
13 Partially correct 16 ms 344 KB Output is partially correct
14 Partially correct 17 ms 448 KB Output is partially correct
15 Partially correct 17 ms 452 KB Output is partially correct
16 Partially correct 17 ms 344 KB Output is partially correct
17 Partially correct 17 ms 452 KB Output is partially correct
18 Partially correct 17 ms 344 KB Output is partially correct
19 Partially correct 17 ms 344 KB Output is partially correct
20 Partially correct 17 ms 344 KB Output is partially correct
21 Partially correct 17 ms 344 KB Output is partially correct
22 Partially correct 19 ms 592 KB Output is partially correct
23 Partially correct 13 ms 452 KB Output is partially correct
24 Partially correct 17 ms 344 KB Output is partially correct
25 Partially correct 17 ms 344 KB Output is partially correct
26 Partially correct 16 ms 344 KB Output is partially correct
27 Partially correct 17 ms 344 KB Output is partially correct
28 Partially correct 16 ms 344 KB Output is partially correct
29 Partially correct 16 ms 344 KB Output is partially correct
30 Partially correct 17 ms 452 KB Output is partially correct
31 Partially correct 16 ms 344 KB Output is partially correct
32 Partially correct 20 ms 600 KB Output is partially correct
33 Partially correct 17 ms 456 KB Output is partially correct
34 Partially correct 12 ms 344 KB Output is partially correct
35 Partially correct 16 ms 344 KB Output is partially correct
36 Partially correct 16 ms 344 KB Output is partially correct
37 Partially correct 16 ms 344 KB Output is partially correct
38 Partially correct 14 ms 456 KB Output is partially correct
39 Partially correct 16 ms 344 KB Output is partially correct
40 Partially correct 14 ms 344 KB Output is partially correct