Submission #978527

# Submission time Handle Problem Language Result Execution time Memory
978527 2024-05-09T09:55:41 Z salmon Koala Game (APIO17_koala) C++14
100 / 100
86 ms 964 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] = 8;
    in[b] = 8;

    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();
}

vector<int> functon(vector<int> input, int num){
    int in[100], res[100];
    set<int> sat;
    vector<int> v1;

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

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

    for(int i = 1; i < 2; i++){
        playRound(in,res);

        for(int i = 0; i < 100; i++){
            if(res[i] > in[i] && sat.find(i) != sat.end()){
                v1.push_back(i);
            }
        }
    }
    //printf("%d\n",v1.size());
    return v1;
}

vector<int> functin(vector<int> input, vector<int> n, int num){
    int in[100], res[100];
    set<int> sat;
    set<int> sat1;
    vector<int> v1;

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

    for(int i : n){
        sat1.insert(i);
    }

    for(int i = 0; i < input.size(); i++){
        if(sat1.find(input[i]) != sat1.end() ) continue;
        in[input[i]] = num;
        sat.insert(input[i]);
    }

    for(int i = 1; i < 2; i++){
        playRound(in,res);

        for(int i = 0; i < 100; i++){
            if(res[i] > in[i] && sat.find(i) != sat.end()){
                v1.push_back(i);
            }
        }
    }
    //printf("%d\n",v1.size());
    return v1;
}
vector<int> order;

vector<int> functun(vector<int> input, vector<int> n, int num, int fum){
    int in[100], res[100];
    set<int> sat;
    set<int> sat1;
    vector<int> v1;

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

    for(int i : n){
        sat1.insert(i);
        in[i] = fum;
    }
    in[order[49]] = 3;
    for(int i = 0; i < input.size(); i++){
        if(sat1.find(input[i]) != sat1.end() ) continue;
        in[input[i]] = num;
        sat.insert(input[i]);
    }

    for(int i = 1; i < 2; i++){
        playRound(in,res);

        for(int i = 0; i < 100; i++){
            if(res[i] > in[i] && sat.find(i) != sat.end()){
                v1.push_back(i);
            }
        }
    }
    //printf("%d\n",v1.size());
    return v1;
}

vector<int> functan(vector<int> input, vector<int> n, int num, int fum){
    int in[100], res[100];
    set<int> sat;
    set<int> sat1;
    vector<int> v1;

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

    int lum = 0;
    for(int i : n){
        sat1.insert(i);
        if(lum <= 22) in[i] = fum;
        lum++;
    }

    for(int i = 0; i < input.size(); i++){
        if(sat1.find(input[i]) != sat1.end() ) continue;
        in[input[i]] = num;
        sat.insert(input[i]);
    }

    for(int i = 1; i < 2; i++){
        playRound(in,res);

        for(int i = 0; i < 100; i++){
            if(res[i] > in[i] && sat.find(i) != sat.end()){
                v1.push_back(i);
            }
        }
    }
    return v1;
}

vector<int> functen(vector<int> input, vector<int> n, int num, int fum){
    int in[100], res[100];
    set<int> sat;
    set<int> sat1;
    vector<int> v1;

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

    int lum = 0;
    for(int i : n){
        sat1.insert(i);
        if(lum <= 20) in[i] = fum;
        lum++;
    }

    for(int i = 0; i < input.size(); i++){
        if(sat1.find(input[i]) != sat1.end() ) continue;
        in[input[i]] = num;
        sat.insert(input[i]);
    }

    for(int i = 1; i < 2; i++){
        playRound(in,res);

        for(int i = 0; i < 100; i++){
            if(res[i] > in[i] && sat.find(i) != sat.end()){
                v1.push_back(i);
            }
        }
    }
    return v1;
}

vector<int> functqn(vector<int> input, vector<int> n, int num, int fum, int x){
    int in[100], res[100];
    set<int> sat;
    set<int> sat1;
    vector<int> v1;

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

    int lum = 0;
    for(int i : n){
        sat1.insert(i);
        if(lum <= x) in[i] = fum;
        lum++;
    }

    for(int i = 0; i < input.size(); i++){
        if(sat1.find(input[i]) != sat1.end() ) continue;
        in[input[i]] = num;
        sat.insert(input[i]);
    }

    for(int i = 1; i < 2; i++){
        playRound(in,res);

        for(int i = 0; i < 100; i++){
            if(res[i] > in[i] && sat.find(i) != sat.end()){
                v1.push_back(i);
            }
        }
    }
    //printf("%d\n",v1.size());
    return v1;
}

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];
        set<int> sat;
        set<int> tempsat;
        set<int> sad;
        vector<int> input;
        vector<int> v;
        vector<int> v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16,v17,v18,v19,v20,v21,v22,v23,v24,v25,v26,v27,v28,v29,v30,v31,v32,v33;
        vector<vector<int>> vl;
        vector<vector<int>> vv;
        order.clear();

        for(int i = 0; i < N; i++){
            P[i] = -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]){
                input.push_back(i);
            }
        }

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

        for(int i = 0; i < 49; i++){
            in[*(sad.begin())] = 0;
            sad.erase(sad.begin());
            in[*(sad.begin())] = 0;
            sad.erase(sad.begin());

            playRound(in,res);

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

        order.push_back(*(sat.begin()));

        reverse(order.begin(),order.end());

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


        v1 = functon(input, 2);
        v2 = functon(v1, 4);

        v3 = functon(v2, 11);

        vl.push_back(v3);

        for(int i = 0; i < 8; i++){
            vector<int> temp = functin(v2, vl.back(), 10);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }

        //10 done

        for(int i = 0; i < 2; i++){
            vector<int> temp = functun(v1, vl.back(), 4, 3);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }
        for(int i = 0; i < 2; i++){
            vector<int> temp = functun(v1, vl.back(), 5, 2);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }
        for(int i = 0; i < 3; i++){
            vector<int> temp = functun(v1, vl.back(), 6, 1);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }
        for(int i = 0; i < 3; i++){
            vector<int> temp = functun(v1, vl.back(), 5, 1);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }
        for(int i = 0; i < 5; i++){
            vector<int> temp = functun(v1, vl.back(), 8, 0);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }

        vl.push_back(v1);

        //25

        for(int i = 0; i < 2; i++){
            vector<int> temp = functan(input, vl.back(), 2, 2);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }
        for(int i = 0; i < 3; i++){
            vector<int> temp = functen(input, vl.back(), 2, 2);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }

        for(int i = 0; i < 3; i++){
            vector<int> temp = functqn(input, vl.back(), 2, 2, 18);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }

        for(int i = 0; i < 2; i++){
            vector<int> temp = functqn(input, vl.back(), 2, 2, 16);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }

        for(int i = 0; i < 5; i++){
            vector<int> temp = functqn(input, vl.back(), 5, 1, 16);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }

        for(int i = 0; i < 5; i++){
            vector<int> temp = functqn(input, vl.back(), 4, 1, 13);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }

        for(int i = 0; i < 4; i++){
            vector<int> temp = functqn(input, vl.back(), 4, 1, 7);
            temp.insert(temp.end(), vl.back().begin(), vl.back().end());
            vl.push_back(temp);
        }

        sat.clear();
        int cont = 100;
        for(vector<int> v : vl){
            for(int i : v){
                if(sat.find(i) == sat.end()){
                    P[i] = cont;
                    cont--;
                    sat.insert(i);
                }
            }
        }

        vector<int> temp;
        for(int i : input){
            if(sat.find(i) == sat.end()) temp.push_back(i);
        }
        input = temp;

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

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

        for(int i = 0; i < order.size(); i++){
            P[order[i]] = i + 1;
        }
    }
}

Compilation message

koala.cpp: In function 'std::vector<int> sblort(std::vector<int>)':
koala.cpp:158:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  158 |         for(int i = 0; i < v1.size() + v2.size() - 1; i++){
      |                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp: In function 'std::vector<int> functon(std::vector<int>, int)':
koala.cpp:186:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  186 |     for(int i = 0; i < input.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
koala.cpp: In function 'std::vector<int> functin(std::vector<int>, std::vector<int>, int)':
koala.cpp:218:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  218 |     for(int i = 0; i < input.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
koala.cpp: In function 'std::vector<int> functun(std::vector<int>, std::vector<int>, int, int)':
koala.cpp:253:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  253 |     for(int i = 0; i < input.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
koala.cpp: In function 'std::vector<int> functan(std::vector<int>, std::vector<int>, int, int)':
koala.cpp:289:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  289 |     for(int i = 0; i < input.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
koala.cpp: In function 'std::vector<int> functen(std::vector<int>, std::vector<int>, int, int)':
koala.cpp:324:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  324 |     for(int i = 0; i < input.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
koala.cpp: In function 'std::vector<int> functqn(std::vector<int>, std::vector<int>, int, int, int)':
koala.cpp:359:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  359 |     for(int i = 0; i < input.size(); i++){
      |                    ~~^~~~~~~~~~~~~~
koala.cpp: In function 'void allValues(int, int, int*)':
koala.cpp:400:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  400 |             for(int i = 0; i < v1.size() + v2.size() - 1; i++){
      |                            ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
koala.cpp:596:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  596 |         for(int i = 0; i < order.size(); 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:138:1: warning: control reaches end of non-void function [-Wreturn-type]
  138 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 344 KB Output is correct
2 Correct 12 ms 344 KB Output is correct
3 Correct 12 ms 344 KB Output is correct
4 Correct 11 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 460 KB Output is correct
2 Correct 68 ms 460 KB Output is correct
3 Correct 70 ms 460 KB Output is correct
4 Correct 69 ms 484 KB Output is correct
5 Correct 70 ms 464 KB Output is correct
6 Correct 70 ms 464 KB Output is correct
7 Correct 75 ms 964 KB Output is correct
8 Correct 71 ms 464 KB Output is correct
9 Correct 86 ms 460 KB Output is correct
10 Correct 69 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 456 KB Output is correct
2 Correct 28 ms 344 KB Output is correct
3 Correct 26 ms 344 KB Output is correct
4 Correct 25 ms 344 KB Output is correct
5 Correct 31 ms 344 KB Output is correct
6 Correct 26 ms 344 KB Output is correct
7 Correct 25 ms 344 KB Output is correct
8 Correct 25 ms 344 KB Output is correct
9 Correct 29 ms 460 KB Output is correct
10 Correct 25 ms 344 KB Output is correct
11 Correct 25 ms 460 KB Output is correct
12 Correct 17 ms 456 KB Output is correct
13 Correct 25 ms 344 KB Output is correct
14 Correct 23 ms 340 KB Output is correct
15 Correct 23 ms 344 KB Output is correct
16 Correct 22 ms 344 KB Output is correct
17 Correct 23 ms 344 KB Output is correct
18 Correct 23 ms 460 KB Output is correct
19 Correct 23 ms 344 KB Output is correct
20 Correct 22 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 344 KB Output is correct
2 Correct 4 ms 344 KB Output is correct
3 Correct 4 ms 452 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 3 ms 344 KB Output is correct
6 Correct 3 ms 344 KB Output is correct
7 Correct 3 ms 344 KB Output is correct
8 Correct 3 ms 344 KB Output is correct
9 Correct 3 ms 344 KB Output is correct
10 Correct 3 ms 344 KB Output is correct
11 Correct 3 ms 344 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 3 ms 456 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 3 ms 344 KB Output is correct
16 Correct 3 ms 344 KB Output is correct
17 Correct 3 ms 456 KB Output is correct
18 Correct 3 ms 344 KB Output is correct
19 Correct 3 ms 344 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 3 ms 344 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 3 ms 344 KB Output is correct
24 Correct 3 ms 344 KB Output is correct
25 Correct 3 ms 344 KB Output is correct
26 Correct 3 ms 344 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 3 ms 344 KB Output is correct
29 Correct 3 ms 344 KB Output is correct
30 Correct 3 ms 344 KB Output is correct
31 Correct 3 ms 452 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 3 ms 344 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 3 ms 344 KB Output is correct
36 Correct 3 ms 452 KB Output is correct
37 Correct 4 ms 344 KB Output is correct
38 Correct 3 ms 344 KB Output is correct
39 Correct 3 ms 344 KB Output is correct
40 Correct 3 ms 460 KB Output is correct