Submission #56544

# Submission time Handle Problem Language Result Execution time Memory
56544 2018-07-11T15:17:45 Z andremfq Koala Game (APIO17_koala) C
47 / 100
107 ms 824 KB
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "koala.h"

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define true 1
#define false 0

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

int maxValue(int N, int W) {
    int B[N+5];
    int R[N+5];
    int setSize = N;
    int inSet[N+5];
    FO (i,0,N) inSet[i] = 1;
    while (setSize > 1) {
        FO (i,0,N) {
            if (inSet[i]) {
                B[i] = W/setSize;
            } else {
                B[i] = 0;
            }
        }
        playRound(B,R);
        setSize = 0;
        FO (i,0,N) {
            if (R[i] > B[i] && inSet[i]) {
                inSet[i] = true;
                setSize++;
            } else {
                inSet[i] = false;
            }
        }
    }
    FO (i,0,N) {
        if (inSet[i]) return i;
    }
}

int greaterValue(int N, int W) {
    int B[N+5], R[N+5];
    int vals[4] = {1,3,6,8};
    int lo = 0;
    int hi = 3;
    int mid;
    while (lo <= hi) {
        mid = (lo+hi)/2;
        FO (i,0,N) B[i] = 0;
        B[0] = B[1] = vals[mid];
        playRound(B,R);
        if (R[0] > B[0] && R[1] > B[1]) {
            lo = mid+1;
        } else if (R[0] <= B[0] && R[1] <= B[1]) {
            hi = mid-1;
        } else if (R[0] > B[0]) {
            return 0;
        } else {
            return 1;
        }
    }
    assert(false);
}

int *sortRange(int *, int);
void allValues(int N, int W, int *P) {
    if (W == 2*N) {
        int startV[105];
        FO (i,0,N) startV[i] = i;
        int *finalV = sortRange(startV, N);
        FO (i,0,N) {
            P[finalV[i]] = N-i;
        }
    } else {
        // TODO: Implement Subtask 5 solution here.
        // You may leave this block unmodified if you are not attempting this
        // subtask.
    }
}

int B[105], R[105];

int *sortRange(int *A, int nA) {
    int *cpA = malloc(sizeof(int)*nA);
    memcpy (cpA, A, nA*sizeof(int));
    if (nA == 1) return cpA;
    int ofC[nA/2+1];
    int osC[nA/2+1];
    int ofN = 0;
    int osN = 0;
    FO (i,0,nA) {
        if (i%2) {
            osC[osN++] = A[i];
        } else {
            ofC[ofN++] = A[i];
        }
    }
    int *f = sortRange(ofC, ofN);
    int *s = sortRange(osC, osN);
    int fN = 0;
    int sN = 0;
    int aN = 0;
    while (fN < ofN || sN < osN) {
        if (fN == ofN) {
            cpA[aN++] = s[sN++];
        } else if (sN == osN) {
            cpA[aN++] = f[fN++];
        } else {
            FO (i,0,100) B[i] = 0;
            B[f[fN]] = B[s[sN]] = 100;
            playRound(B,R);
            if (R[f[fN]] > B[f[fN]]) {
                cpA[aN++] = f[fN++];
            } else {
                cpA[aN++] = s[sN++];
            }
        }
    }
    return cpA;
}

Compilation message

koala.c: In function 'maxValue':
koala.c:52:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 248 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Correct 9 ms 448 KB Output is correct
4 Correct 7 ms 448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 448 KB Output is correct
2 Correct 19 ms 536 KB Output is correct
3 Correct 21 ms 540 KB Output is correct
4 Correct 22 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 672 KB Output is correct
2 Correct 96 ms 672 KB Output is correct
3 Correct 100 ms 672 KB Output is correct
4 Correct 83 ms 672 KB Output is correct
5 Correct 95 ms 672 KB Output is correct
6 Correct 107 ms 720 KB Output is correct
7 Correct 105 ms 812 KB Output is correct
8 Correct 105 ms 812 KB Output is correct
9 Correct 100 ms 812 KB Output is correct
10 Correct 104 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 824 KB Output is correct
2 Correct 49 ms 824 KB Output is correct
3 Correct 35 ms 824 KB Output is correct
4 Correct 45 ms 824 KB Output is correct
5 Correct 41 ms 824 KB Output is correct
6 Correct 41 ms 824 KB Output is correct
7 Correct 38 ms 824 KB Output is correct
8 Correct 53 ms 824 KB Output is correct
9 Correct 59 ms 824 KB Output is correct
10 Correct 42 ms 824 KB Output is correct
11 Correct 56 ms 824 KB Output is correct
12 Correct 38 ms 824 KB Output is correct
13 Correct 38 ms 824 KB Output is correct
14 Correct 65 ms 824 KB Output is correct
15 Correct 52 ms 824 KB Output is correct
16 Correct 44 ms 824 KB Output is correct
17 Correct 61 ms 824 KB Output is correct
18 Correct 51 ms 824 KB Output is correct
19 Correct 58 ms 824 KB Output is correct
20 Correct 40 ms 824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 824 KB Output isn't correct
2 Halted 0 ms 0 KB -