답안 #392468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
392468 2021-04-21T08:13:07 Z MarcoMeijer 코알라 (APIO17_koala) C++14
100 / 100
82 ms 448 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);
}
ii simulate(int N, int lb, int ub, int weight) {
    vi stck;
    REV(i,1,N+1) if(i < lb || i > ub) stck.push_back(i);
    REP(_,lb,ub+1) stck.push_back(0);

    int x = ub;
    while(stck.size() > weight && x >= lb) {
        int sm = 0;
        RE(_,weight+1) sm += stck.back(), stck.pop_back();
        if(sm < x) x--;
        else break;
    }

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

    bool triedHelp = false;

    int LB=1, UB=W/f.size();
    while(LB != UB) {
        int mid=(LB+UB)/2;
        ii p = simulate(N,lb,ub,mid);
        if(p.fi < p.se) LB=mid+1;
        else UB=mid;
    }

    RE(i,N) B[i] = 0;
    FOR(u,f) B[u] = LB;
    playRound(B,R);
    vi left;
    vi right;
    FOR(u,f) (R[u] > LB ? right : left).push_back(u);
    findValues2(N,W,lb,lb+left.size()-1,left,P);
    findValues2(N,W,ub-right.size()+1,ub,right,P);
}

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

Compilation message

koala.cpp: In function 'ii simulate(int, int, int, int)':
koala.cpp:107:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  107 |     while(stck.size() > weight && x >= lb) {
      |           ~~~~~~~~~~~~^~~~~~~~
koala.cpp: In function 'void findValues2(int, int, int, int, vi, int*)':
koala.cpp:122:10: warning: unused variable 'triedHelp' [-Wunused-variable]
  122 |     bool triedHelp = false;
      |          ^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 200 KB Output is correct
2 Correct 6 ms 324 KB Output is correct
3 Correct 6 ms 200 KB Output is correct
4 Correct 6 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 200 KB Output is correct
2 Correct 18 ms 316 KB Output is correct
3 Correct 18 ms 200 KB Output is correct
4 Correct 22 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 336 KB Output is correct
2 Correct 80 ms 324 KB Output is correct
3 Correct 71 ms 324 KB Output is correct
4 Correct 71 ms 328 KB Output is correct
5 Correct 73 ms 332 KB Output is correct
6 Correct 74 ms 448 KB Output is correct
7 Correct 76 ms 324 KB Output is correct
8 Correct 73 ms 332 KB Output is correct
9 Correct 74 ms 328 KB Output is correct
10 Correct 71 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 200 KB Output is correct
2 Correct 9 ms 328 KB Output is correct
3 Correct 9 ms 200 KB Output is correct
4 Correct 10 ms 320 KB Output is correct
5 Correct 9 ms 200 KB Output is correct
6 Correct 9 ms 328 KB Output is correct
7 Correct 8 ms 320 KB Output is correct
8 Correct 9 ms 328 KB Output is correct
9 Correct 8 ms 328 KB Output is correct
10 Correct 10 ms 328 KB Output is correct
11 Correct 9 ms 320 KB Output is correct
12 Correct 9 ms 200 KB Output is correct
13 Correct 9 ms 324 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 200 KB Output is correct
17 Correct 8 ms 324 KB Output is correct
18 Correct 8 ms 200 KB Output is correct
19 Correct 9 ms 320 KB Output is correct
20 Correct 9 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 200 KB Output is correct
2 Correct 5 ms 200 KB Output is correct
3 Correct 5 ms 200 KB Output is correct
4 Correct 5 ms 328 KB Output is correct
5 Correct 5 ms 316 KB Output is correct
6 Correct 5 ms 328 KB Output is correct
7 Correct 5 ms 200 KB Output is correct
8 Correct 5 ms 328 KB Output is correct
9 Correct 6 ms 328 KB Output is correct
10 Correct 5 ms 200 KB Output is correct
11 Correct 6 ms 200 KB Output is correct
12 Correct 5 ms 328 KB Output is correct
13 Correct 5 ms 200 KB Output is correct
14 Correct 5 ms 332 KB Output is correct
15 Correct 5 ms 200 KB Output is correct
16 Correct 5 ms 200 KB Output is correct
17 Correct 6 ms 328 KB Output is correct
18 Correct 5 ms 328 KB Output is correct
19 Correct 5 ms 328 KB Output is correct
20 Correct 5 ms 200 KB Output is correct
21 Correct 5 ms 328 KB Output is correct
22 Correct 5 ms 200 KB Output is correct
23 Correct 5 ms 328 KB Output is correct
24 Correct 5 ms 200 KB Output is correct
25 Correct 5 ms 200 KB Output is correct
26 Correct 5 ms 328 KB Output is correct
27 Correct 5 ms 200 KB Output is correct
28 Correct 5 ms 328 KB Output is correct
29 Correct 5 ms 200 KB Output is correct
30 Correct 5 ms 324 KB Output is correct
31 Correct 5 ms 200 KB Output is correct
32 Correct 5 ms 200 KB Output is correct
33 Correct 5 ms 328 KB Output is correct
34 Correct 5 ms 200 KB Output is correct
35 Correct 5 ms 200 KB Output is correct
36 Correct 5 ms 200 KB Output is correct
37 Correct 5 ms 200 KB Output is correct
38 Correct 5 ms 324 KB Output is correct
39 Correct 5 ms 200 KB Output is correct
40 Correct 5 ms 328 KB Output is correct