Submission #66849

# Submission time Handle Problem Language Result Execution time Memory
66849 2018-08-12T14:14:39 Z Benq Koala Game (APIO17_koala) C++14
37 / 100
108 ms 3568 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

// #define LOCAL 

#ifdef LOCAL 
    void playRound(int *B, int *R);
#else
    #include "koala.h"
#endif

int B[100], R[100];

void clr() {
    F0R(i,100) B[i] = 0;
}

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

void prin() {
    F0R(i,100) cout << B[i] << " ";
    cout << "\n";
    F0R(i,100) cout << R[i] << " ";
    cout << "\n";
}

void upd(vi& v) {
    vi V; for (int i: v) if (R[i] > B[i]) V.pb(i);
    v = V;
}

int maxValue(int N, int W) {
    vi cand; F0R(i,N) cand.pb(i);
    while (sz(cand) > 1) {
        clr(); for (int i: cand) B[i] = 100/sz(cand); 
        playRound(B,R); 
        upd(cand);
    }
    return cand[0];
}

int greaterValue(int N, int W) {
    /*F0R(i,51) {
        B[0] = B[1] = i;
        playRound(B,R);
        cout << i << " " << R[0] << " " << R[1] << "\n";
    }*/
    int lo = 1, hi = 9;
    while (1) {
        int mid = (lo+hi)/2;
        clr(); B[0] = B[1] = mid;
        playRound(B,R);
        if (R[0] > B[0]) {
            if (R[1] > B[1]) {
                lo = mid+1;
            } else {
                return 0;
            }
        } else {
            if (R[1] > B[1]) {
                return 1;
            } else {
                hi = mid-1;
            }
        }
    }
    return 0;
    // TODO: Implement Subtask 3 solution here.
    // You may leave this function unmodified if you are not attempting this
    // subtask.
    return 0;
}

void allValues(int N, int W, int *P) {
    if (W == 2*N) {
        // TODO: Implement Subtask 4 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    } else {
        // TODO: Implement Subtask 5 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    }
}

#ifdef LOCAL 
static int N, W;
static int P[105];

static int maxQueries = 3200;
static int numQueries;

static void runGame(int F);
static void grader();

int main() {
    grader();
    return 0;
}

void playRound(int *B, int *R) {
    int i, j;

    int S = 0;
    for (i=0;i<N;++i) {
        if ( !(B[i] >= 0 && B[i] <= W) ) {
            printf("Invalid query.\n");
            exit(0);
        }
        S += B[i];
    }
    if (S > W) {
        printf("Invalid query.\n");
        exit(0);
    }

    numQueries++;
    if (numQueries > maxQueries) {
        printf("Too many queries.\n");
        exit(0);
    }

    int cache[2][205];
    int num[2][205];
    char taken[105][205];

    for (i=0;i<205;++i) {
        cache[1][i] = 0;
        num[1][i] = 0;
    }

    for (i=0;i<N;++i) {
        int v = B[i]+1;
        int ii = i&1;
        int o = ii^1;
        for (j=0;j<=W;++j) {
            cache[ii][j] = cache[o][j];
            num[ii][j] = num[o][j];
            taken[i][j] = 0;
        }
        for (j=W;j>=v;--j) {
            int h = cache[o][j-v] + P[i];
            int hn = num[o][j-v] + 1;
            if (h > cache[ii][j] || (h == cache[ii][j] && hn > num[ii][j])) {
                cache[ii][j] = h;
                num[ii][j] = hn;
                taken[i][j] = 1;
            } else {
                taken[i][j] = 0;
            }
        }
    }

    int cur = W;
    for (i=N-1;i>=0;--i) {
        R[i] = taken[i][cur] ? (B[i] + 1) : 0;
        cur -= R[i];
    }
}

static void runGame(int F) {
    int i;

    scanf("%d %d",&N,&W);
    for (i=0;i<N;++i) {
        scanf("%d",&P[i]);
    }

    numQueries = 0;
    if (F == 1) {
        printf("%d\n", minValue(N, W));
    } else if (F == 2) {
        printf("%d\n", maxValue(N, W));
    } else if (F == 3) {
        printf("%d\n", greaterValue(N, W));
    } else if (F == 4) {
        int userP[105];
        allValues(N, W, userP);
        for (i=0;i<N;i++) {
            printf("%d ",userP[i]);
        }
        printf("\n");
    }
    printf("Made %d calls to playRound.\n", numQueries);
}

static void grader() {
    int i;

    int F, G;
    scanf("%d %d",&F,&G);

    for (i=0;i<G;i++) {
        runGame(F);
    }
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 532 KB Output is correct
3 Correct 8 ms 532 KB Output is correct
4 Correct 7 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 720 KB Output is correct
2 Correct 17 ms 720 KB Output is correct
3 Correct 19 ms 720 KB Output is correct
4 Correct 18 ms 720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 71 ms 792 KB Output is correct
2 Correct 82 ms 1060 KB Output is correct
3 Correct 75 ms 1264 KB Output is correct
4 Correct 69 ms 1724 KB Output is correct
5 Correct 67 ms 2036 KB Output is correct
6 Correct 76 ms 2400 KB Output is correct
7 Correct 64 ms 2712 KB Output is correct
8 Correct 102 ms 3056 KB Output is correct
9 Correct 108 ms 3244 KB Output is correct
10 Correct 104 ms 3568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 3568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 3568 KB Output isn't correct
2 Halted 0 ms 0 KB -