Submission #1075460

# Submission time Handle Problem Language Result Execution time Memory
1075460 2024-08-26T06:31:20 Z HappyCapybara Koala Game (APIO17_koala) C++17
77 / 100
57 ms 476 KB
#include "koala.h"
#include<bits/stdc++.h>
using namespace std;

int minValue(int N, int W) {
    int B[N], R[N];
    for (int i=0; i<N; i++) B[i] = 0;
    B[0] = 1;
    playRound(B, R);
    for (int i=0; i<N; i++){
        if (B[i] >= R[i]) return i;
    }
}

int maxValue(int N, int W) {
    int B[N], R[N];
    for (int i=0; i<N; i++) B[i] = 1;
    playRound(B, R);
    vector<int> v;
    for (int i=0; i<N; i++){
        if (R[i] > 1) v.push_back(i);
    }
    //cout << v.size() << "\n";
    for (int i=0; i<N; i++) B[i] = 0;
    for (int x : v) B[x] = 2;
    playRound(B, R);
    vector<int> w;
    for (int x : v){
        if (R[x] > 2) w.push_back(x);
    }
    //cout << w.size() << "\n";
    for (int i=0; i<N; i++) B[i] = 0;
    for (int x : w) B[x] = 4;
    playRound(B, R);
    vector<int> u;
    for (int x : w){
        if (R[x] > 4) u.push_back(x);
    }
    //cout << u.size() << "\n";
    for (int i=0; i<N; i++) B[i] = 0;
    for (int x : u) B[x] = 11;
    playRound(B, R);
    for (int x : u){
        if (R[x] > 11) return x;
    }
}

int greaterValue(int N, int W) {
    int B[N], R[N];
    for (int i=0; i<N; i++) B[i] = 0;
    int l = 0, r = 13;
    while (l != r){
        int m = (l+r)/2;
        B[0] = m;
        B[1] = m;
        playRound(B, R);
        if (R[0] > B[0] && R[1] > B[1]) l = m;
        if (R[0] <= B[0] && R[1] <= B[1]) r = m;
        if (R[0] > B[0] && R[1] <= B[1]) return 0;
        if (R[0] <= B[0] && R[1] > B[1]) return 1;
    }
}

int comp(int a, int b){
    int N = 100;
    int B[N], R[N];
    for (int i=0; i<N; i++) B[i] = 0;
    int l = 1, r = 14;
    while (l != r){
        int m = (l+r)/2;
        B[a] = m;
        B[b] = m;
        playRound(B, R);
        if (R[a] > B[a] && R[b] > B[b]) l = m;
        if (R[a] <= B[a] && R[b] <= B[b]) r = m;
        if (R[a] > B[a] && R[b] <= B[b]) return 0;
        if (R[a] <= B[a] && R[b] > B[b]) return 1;
    }
}

vector<int> sort2(vector<int> v){
    if (v.size() == 1) return v;
    if (v.size() == 2){
        if (comp(v[0], v[1])) return v;
        else return {v[1], v[0]};
    }
    int l = v.size()/2;
    int r = v.size()-l;
    vector<int> a(l);
    vector<int> b(r);
    for (int i=0; i<l; i++) a[i] = v[i];
    for (int i=0; i<r; i++) b[i] = v[i+l];
    a = sort2(a);
    b = sort2(b);
    vector<int> w;
    int c = 0, d = 0;
    while (c+d < l+r){
        if (c == l){
            w.push_back(b[d]);
            d++;
            continue;
        }
        if (d == r){
            w.push_back(a[c]);
            c++;
            continue;
        }
        if (comp(a[c], b[d])){
            w.push_back(a[c]);
            c++;
        }
        else {
            w.push_back(b[d]);
            d++;
        }
    }
    return w;
}

int comp2(int a, int b){
    int N = 100;
    int B[N], R[N];
    for (int i=0; i<N; i++) B[i] = 0;
    B[a] = 100;
    B[b] = 100;
    playRound(B, R);
    if (R[b] > 100) return 1;
    else return 0;
}

vector<int> sort3(vector<int> v){
    if (v.size() == 1) return v;
    if (v.size() == 2){
        if (comp2(v[0], v[1])) return v;
        else return {v[1], v[0]};
    }
    int l = v.size()/2;
    int r = v.size()-l;
    vector<int> a(l);
    vector<int> b(r);
    for (int i=0; i<l; i++) a[i] = v[i];
    for (int i=0; i<r; i++) b[i] = v[i+l];
    a = sort3(a);
    b = sort3(b);
    vector<int> w;
    int c = 0, d = 0;
    while (c+d < l+r){
        if (c == l){
            w.push_back(b[d]);
            d++;
            continue;
        }
        if (d == r){
            w.push_back(a[c]);
            c++;
            continue;
        }
        if (comp2(a[c], b[d])){
            w.push_back(a[c]);
            c++;
        }
        else {
            w.push_back(b[d]);
            d++;
        }
    }
    return w;
}

void allValues(int N, int W, int *P) {
    if (W == 2*N){
        vector<int> v(100);
        for (int i=0; i<100; i++) v[i] = i;
        vector<int> w = sort3(v);
        for (int i=0; i<N; i++) P[w[i]] = i+1;
        return;
    }
    else {
        vector<int> v(100);
        for (int i=0; i<100; i++) v[i] = i;
        vector<int> w = sort2(v);
        for (int i=0; i<N; i++) P[w[i]] = i+1;
        return;
    }
}

Compilation message

koala.cpp: In function 'int minValue(int, int)':
koala.cpp:13:1: warning: control reaches end of non-void function [-Wreturn-type]
   13 | }
      | ^
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:19:17: warning: control reaches end of non-void function [-Wreturn-type]
   19 |     vector<int> v;
      |                 ^
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:62:1: warning: control reaches end of non-void function [-Wreturn-type]
   62 | }
      | ^
koala.cpp: In function 'int comp(int, int)':
koala.cpp:79:1: warning: control reaches end of non-void function [-Wreturn-type]
   79 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 344 KB Output is correct
2 Correct 3 ms 344 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 452 KB Output is correct
2 Correct 11 ms 344 KB Output is correct
3 Correct 13 ms 452 KB Output is correct
4 Correct 10 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 344 KB Output is correct
2 Correct 57 ms 344 KB Output is correct
3 Correct 37 ms 456 KB Output is correct
4 Correct 35 ms 452 KB Output is correct
5 Correct 34 ms 476 KB Output is correct
6 Correct 49 ms 460 KB Output is correct
7 Correct 39 ms 468 KB Output is correct
8 Correct 37 ms 460 KB Output is correct
9 Correct 37 ms 472 KB Output is correct
10 Correct 45 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 344 KB Output is correct
2 Correct 29 ms 344 KB Output is correct
3 Correct 31 ms 456 KB Output is correct
4 Correct 27 ms 344 KB Output is correct
5 Correct 26 ms 344 KB Output is correct
6 Correct 29 ms 428 KB Output is correct
7 Correct 28 ms 456 KB Output is correct
8 Correct 25 ms 344 KB Output is correct
9 Correct 26 ms 344 KB Output is correct
10 Correct 24 ms 344 KB Output is correct
11 Correct 38 ms 344 KB Output is correct
12 Correct 20 ms 344 KB Output is correct
13 Correct 25 ms 344 KB Output is correct
14 Correct 25 ms 452 KB Output is correct
15 Correct 23 ms 456 KB Output is correct
16 Correct 23 ms 344 KB Output is correct
17 Correct 23 ms 344 KB Output is correct
18 Correct 28 ms 456 KB Output is correct
19 Correct 23 ms 452 KB Output is correct
20 Correct 23 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 10 ms 344 KB Output is partially correct
2 Partially correct 18 ms 344 KB Output is partially correct
3 Partially correct 19 ms 344 KB Output is partially correct
4 Partially correct 22 ms 448 KB Output is partially correct
5 Partially correct 16 ms 452 KB Output is partially correct
6 Partially correct 24 ms 452 KB Output is partially correct
7 Partially correct 15 ms 344 KB Output is partially correct
8 Partially correct 17 ms 452 KB Output is partially correct
9 Partially correct 15 ms 344 KB Output is partially correct
10 Partially correct 21 ms 452 KB Output is partially correct
11 Partially correct 17 ms 456 KB Output is partially correct
12 Partially correct 13 ms 344 KB Output is partially correct
13 Partially correct 16 ms 344 KB Output is partially correct
14 Partially correct 15 ms 344 KB Output is partially correct
15 Partially correct 17 ms 452 KB Output is partially correct
16 Partially correct 23 ms 452 KB Output is partially correct
17 Partially correct 15 ms 344 KB Output is partially correct
18 Partially correct 15 ms 344 KB Output is partially correct
19 Partially correct 17 ms 456 KB Output is partially correct
20 Partially correct 15 ms 344 KB Output is partially correct
21 Partially correct 18 ms 460 KB Output is partially correct
22 Partially correct 15 ms 456 KB Output is partially correct
23 Partially correct 18 ms 344 KB Output is partially correct
24 Partially correct 23 ms 452 KB Output is partially correct
25 Partially correct 17 ms 452 KB Output is partially correct
26 Partially correct 15 ms 452 KB Output is partially correct
27 Partially correct 25 ms 344 KB Output is partially correct
28 Partially correct 19 ms 344 KB Output is partially correct
29 Partially correct 15 ms 452 KB Output is partially correct
30 Partially correct 21 ms 344 KB Output is partially correct
31 Partially correct 15 ms 344 KB Output is partially correct
32 Partially correct 17 ms 344 KB Output is partially correct
33 Partially correct 18 ms 344 KB Output is partially correct
34 Partially correct 13 ms 452 KB Output is partially correct
35 Partially correct 16 ms 456 KB Output is partially correct
36 Partially correct 15 ms 344 KB Output is partially correct
37 Partially correct 16 ms 452 KB Output is partially correct
38 Partially correct 15 ms 344 KB Output is partially correct
39 Partially correct 16 ms 456 KB Output is partially correct
40 Partially correct 14 ms 344 KB Output is partially correct