Submission #59378

# Submission time Handle Problem Language Result Execution time Memory
59378 2018-07-21T21:40:57 Z duality Koala Game (APIO17_koala) C++11
24 / 100
192 ms 864 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long int LLI;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
#include "koala.h"

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

int maxValue(int N, int W) {
    int i;
    for (i = 0; i < N; i++) B[i] = 1;
    playRound(B,R);
    int c = 0;
    for (i = 0; i < N; i++) {
        if (R[i] == 2) B[i] = 2;
        else B[i] = 0;
    }
    playRound(B,R);
    for (i = 0; i < N; i++) {
        if (R[i] == 3) c++,B[i] = 4;
        else B[i] = 0;
    }
    playRound(B,R);
    for (i = 0; i < N; i++) {
        if (R[i] == 5) B[i] = 11;
        else B[i] = 0;
    }
    playRound(B,R);
    for (i = 0; i < N; i++) {
        if (R[i] == 12) return i;
    }
}

int compare(int a,int b,int N,int W) {
    int i;
    vi poss;
    for (i = 0; i < N; i++) poss.pb(i);
    int l = 1,r = N;
    while (1) {
        for (i = 0; i < N; i++) B[i] = 0;
        int val = 1;
        while (1) {
            int best1 = 0,c = W;
            for (i = N; i >= 1; i--) {
                if ((i < l) || (i > r)) {
                    if (c > 0) best1 += i,c--;
                }
            }
            int best2 = 0;
            c = W;
            for (i = r; i >= l; i--) {
                if (c > val) best2 += i,c -= val+1;
            }
            for (i = N; i >= 1; i--) {
                if ((i < l) || (i > r)) {
                    if (c > 0) best2 += i,c--;
                }
            }
            int best3 = r;
            c = W-(val+1);
            for (i = N; i >= 1; i--) {
                if ((i < l) || (i > r)) {
                    if (c > 0) best3 += i,c--;
                }
            }
            int best4 = 0;
            c = W;
            for (i = r; i > l; i--) {
                if (c > val) best4 += i,c -= val+1;
            }
            for (i = N; i >= 1; i--) {
                if ((i < l) || (i > r)) {
                    if (c > 0) best4 += i,c--;
                }
            }
            if (max(best1,best2) > max(best3,best4)) val++;
            else break;
        }
        if ((val == 1) && (2*poss.size() <= W)) {
            val = 2;
            int best1 = 0,c = W;
            for (i = N; i >= 1; i--) {
                if ((i < l) || (i > r)) {
                    if (c > 0) best1 += i,c--;
                }
            }
            int best2 = 0;
            c = W;
            for (i = r; i >= l; i--) {
                if (c > val) best2 += i,c -= val+1;
            }
            for (i = N; i >= 1; i--) {
                if ((i < l) || (i > r)) {
                    if (c > 0) best2 += i,c--;
                }
            }
            int best3 = r;
            c = W-(val+1);
            for (i = N; i >= 1; i--) {
                if ((i < l) || (i > r)) {
                    if (c > 0) best3 += i,c--;
                }
            }
            int best4 = 0;
            c = W;
            for (i = r; i > l; i--) {
                if (c > val) best4 += i,c -= val+1;
            }
            for (i = N; i >= 1; i--) {
                if ((i < l) || (i > r)) {
                    if (c > 0) best4 += i,c--;
                }
            }
            if (max(best1,best2) > max(best3,best4)) val = 1;
        }
        //cout<<l<<","<<r<<","<<val<<endl;
        for (i = 0; i < poss.size(); i++) B[poss[i]] = val;//min(poss.size()-1,N/poss.size());
        playRound(B,R);
        if ((R[a] > 0) != (R[b] > 0)) return R[b] > 0;
        vi poss2;
        for (i = 0; i < poss.size(); i++) {
            if (R[a] > 0) {
                if (R[poss[i]] > 0) poss2.pb(poss[i]);
            }
            else {
                if (R[poss[i]] == 0) poss2.pb(poss[i]);
            }
        }
        if (R[a] > 0) l = r-poss2.size()+1;
        else r = l+poss2.size()-1;
        poss = poss2;
    }
    return 0;
}
int greaterValue(int N, int W) {
    return compare(0,1,N,W);
}

int n,w;
int inv[100];
bool comp(int a,int b) {
    return compare(a,b,n,w);
}
void allValues(int N, int W, int *P) {
    n = N,w = N;
    if (W == 2*N) {
        // TODO: Implement Subtask 4 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    } else {
        int i;
        for (i = 0; i < N; i++) inv[i] = i;
        sort(inv,inv+N,comp);
        for (i = 0; i < N; i++) P[inv[i]] = i+1;
    }
}

Compilation message

koala.cpp: In function 'int compare(int, int, int, int)':
koala.cpp:93:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if ((val == 1) && (2*poss.size() <= W)) {
                            ~~~~~~~~~~~~~~^~~~
koala.cpp:131:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < poss.size(); i++) B[poss[i]] = val;//min(poss.size()-1,N/poss.size());
                     ~~^~~~~~~~~~~~~
koala.cpp:135:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 0; i < poss.size(); i++) {
                     ~~^~~~~~~~~~~~~
koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 248 KB Output is correct
2 Correct 10 ms 436 KB Output is correct
3 Correct 7 ms 448 KB Output is correct
4 Correct 7 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 580 KB Output is correct
2 Correct 18 ms 592 KB Output is correct
3 Correct 25 ms 592 KB Output is correct
4 Correct 27 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 125 ms 724 KB Output is partially correct
2 Partially correct 192 ms 724 KB Output is partially correct
3 Partially correct 93 ms 724 KB Output is partially correct
4 Partially correct 102 ms 824 KB Output is partially correct
5 Partially correct 103 ms 824 KB Output is partially correct
6 Partially correct 150 ms 824 KB Output is partially correct
7 Partially correct 106 ms 864 KB Output is partially correct
8 Partially correct 105 ms 864 KB Output is partially correct
9 Partially correct 112 ms 864 KB Output is partially correct
10 Partially correct 94 ms 864 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Partially correct 132 ms 864 KB Output is partially correct
2 Incorrect 140 ms 864 KB Output isn't correct
3 Halted 0 ms 0 KB -