Submission #392363

# Submission time Handle Problem Language Result Execution time Memory
392363 2021-04-20T20:47:03 Z MarcoMeijer Koala Game (APIO17_koala) C++14
93 / 100
83 ms 340 KB
#include "koala.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MX=500;

int B[MX], R[MX];

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

int maxValue(int N, int W) {
    vi possible;
    RE(i,N) possible.push_back(i);
    while(possible.size() > 1) {
        int weight = W / possible.size();
        RE(i,N) B[i] = 0;
        FOR(u,possible) B[u] = weight;
        playRound(B,R);
        possible.clear();
        RE(i,N) if(R[i] > weight) possible.push_back(i);
    }
    return possible[0];
}

int greaterValue(int N, int W, int i, int j) {
    int lb=1, ub=10;
    while(lb != ub) {
        int mid=(lb+ub)/2;
        RE(i,N) B[i] = 0;
        B[i] = mid;
        B[j] = mid;
        playRound(B,R);
        if(R[i] <= mid && R[j] <= mid) ub=mid-1;
        if(R[i] >  mid && R[j] >  mid) lb=mid+1;
        if(R[i] <= mid && R[j] >  mid) return j;
        if(R[i] >  mid && R[j] <= mid) return i;
    }
    RE(i,N) B[i] = 0;
    B[i] = lb;
    B[j] = lb;
    playRound(B,R);
    if(R[i] <= lb && R[j] > lb) return j;
    if(R[i] > lb && R[j] <= lb) return i;
    return i;
}

int greaterValue(int N, int W) {
    return greaterValue(N,W,0,1);
}

void findValues1(int N, int W, int lb, int ub, vi f, int *P) {
    if(f.size() == 1) {
        P[f[0]] = lb;
        return;
    }

    int weight = W / f.size();
    RE(i,N) B[i] = 0;
    FOR(u,f) B[u] = weight;
    playRound(B,R);

    vi left;
    vi right;
    FOR(u,f) (R[u] > weight ? right : left).push_back(u);
    findValues1(N,W,lb,lb+left.size()-1,left,P);
    findValues1(N,W,ub-right.size()+1,ub,right,P);
}
void findValues2(int N, int W, int lb, int ub, vi f, int *P) {
    if(f.size() == 1) {
        P[f[0]] = lb;
        return;
    }

    int LB=1, UB=W/f.size();
    while(true) {
        int mid=(LB+UB)/2;
        RE(i,N) B[i] = 0;
        FOR(u,f) B[u] = mid;
        playRound(B,R);
        vi left;
        vi right;
        FOR(u,f) (R[u] > mid ? right : left).push_back(u);
        if(left.empty()) LB=mid+1;
        else if(right.empty()) UB=mid-1;
        else {
            findValues2(N,W,lb,lb+left.size()-1,left,P);
            findValues2(N,W,ub-right.size()+1,ub,right,P);
            break;
        }
    }
}

void allValues(int N, int W, int *P) {
    vi f;
    RE(i,N) f.push_back(i);
    if (W == 2*N) {
        findValues1(N,W,1,N,f,P);
    } else {
        findValues2(N,W,1,N,f,P);
    }
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 204 KB Output is correct
2 Correct 6 ms 328 KB Output is correct
3 Correct 7 ms 200 KB Output is correct
4 Correct 5 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 200 KB Output is correct
2 Correct 18 ms 320 KB Output is correct
3 Correct 19 ms 316 KB Output is correct
4 Correct 18 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 324 KB Output is correct
2 Correct 78 ms 320 KB Output is correct
3 Correct 69 ms 332 KB Output is correct
4 Correct 71 ms 328 KB Output is correct
5 Correct 70 ms 328 KB Output is correct
6 Correct 80 ms 332 KB Output is correct
7 Correct 73 ms 308 KB Output is correct
8 Correct 71 ms 328 KB Output is correct
9 Correct 83 ms 324 KB Output is correct
10 Correct 69 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 328 KB Output is correct
2 Correct 8 ms 328 KB Output is correct
3 Correct 9 ms 200 KB Output is correct
4 Correct 8 ms 200 KB Output is correct
5 Correct 9 ms 324 KB Output is correct
6 Correct 9 ms 200 KB Output is correct
7 Correct 9 ms 200 KB Output is correct
8 Correct 8 ms 300 KB Output is correct
9 Correct 8 ms 328 KB Output is correct
10 Correct 9 ms 328 KB Output is correct
11 Correct 8 ms 200 KB Output is correct
12 Correct 8 ms 328 KB Output is correct
13 Correct 8 ms 200 KB Output is correct
14 Correct 9 ms 200 KB Output is correct
15 Correct 8 ms 200 KB Output is correct
16 Correct 8 ms 328 KB Output is correct
17 Correct 8 ms 328 KB Output is correct
18 Correct 8 ms 200 KB Output is correct
19 Correct 8 ms 200 KB Output is correct
20 Correct 8 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 8 ms 328 KB Output is partially correct
2 Partially correct 8 ms 328 KB Output is partially correct
3 Partially correct 8 ms 200 KB Output is partially correct
4 Partially correct 9 ms 328 KB Output is partially correct
5 Partially correct 9 ms 328 KB Output is partially correct
6 Partially correct 8 ms 200 KB Output is partially correct
7 Partially correct 9 ms 328 KB Output is partially correct
8 Partially correct 8 ms 328 KB Output is partially correct
9 Partially correct 8 ms 324 KB Output is partially correct
10 Partially correct 8 ms 200 KB Output is partially correct
11 Partially correct 8 ms 328 KB Output is partially correct
12 Partially correct 8 ms 324 KB Output is partially correct
13 Partially correct 8 ms 328 KB Output is partially correct
14 Partially correct 9 ms 200 KB Output is partially correct
15 Partially correct 8 ms 324 KB Output is partially correct
16 Partially correct 8 ms 200 KB Output is partially correct
17 Partially correct 8 ms 328 KB Output is partially correct
18 Partially correct 8 ms 328 KB Output is partially correct
19 Partially correct 8 ms 200 KB Output is partially correct
20 Partially correct 8 ms 324 KB Output is partially correct
21 Partially correct 8 ms 328 KB Output is partially correct
22 Partially correct 9 ms 320 KB Output is partially correct
23 Partially correct 8 ms 328 KB Output is partially correct
24 Partially correct 9 ms 268 KB Output is partially correct
25 Partially correct 8 ms 328 KB Output is partially correct
26 Partially correct 8 ms 200 KB Output is partially correct
27 Partially correct 8 ms 324 KB Output is partially correct
28 Partially correct 8 ms 328 KB Output is partially correct
29 Partially correct 8 ms 200 KB Output is partially correct
30 Partially correct 8 ms 328 KB Output is partially correct
31 Partially correct 8 ms 328 KB Output is partially correct
32 Partially correct 8 ms 328 KB Output is partially correct
33 Partially correct 8 ms 332 KB Output is partially correct
34 Partially correct 8 ms 200 KB Output is partially correct
35 Partially correct 8 ms 328 KB Output is partially correct
36 Partially correct 8 ms 200 KB Output is partially correct
37 Partially correct 8 ms 200 KB Output is partially correct
38 Partially correct 8 ms 328 KB Output is partially correct
39 Partially correct 8 ms 328 KB Output is partially correct
40 Partially correct 8 ms 200 KB Output is partially correct