답안 #59380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59380 2018-07-21T22:01:08 Z duality 코알라 (APIO17_koala) C++11
37 / 100
233 ms 996 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,j;
    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,e = N;
        for (i = 1; i <= N/poss.size(); i++) {
            int m1 = 0,m2 = 0,ee = N;
            for (j = 0; j <= N-(r-l+1); j++) {
                int x = min((W-j)/(i+1),r-l+1);
                int sum = (2*N-min(j,N-r)+1)*min(j,N-r)/2;
                sum += (2*(l-1)-(j-min(j,N-r))+1)*(j-min(j,N-r))/2;
                sum += (2*r-x+1)*x/2;
                if ((sum > m1) || ((sum == m1) && (j+x > m2))) {
                    m1 = sum,m2 = j+x;
                    ee = max(x,r-l+1-x);
                }
            }
            if (ee < e) e = ee,val = i;
        }
        //cout<<l<<","<<r<<","<<val<<","<<e<<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;
        random_shuffle(inv,inv+N);
        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:56:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (i = 1; i <= N/poss.size(); i++) {
                     ~~^~~~~~~~~~~~~~~~
koala.cpp:71: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:75: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]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 376 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Correct 8 ms 428 KB Output is correct
4 Correct 9 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 476 KB Output is correct
2 Correct 28 ms 540 KB Output is correct
3 Correct 19 ms 760 KB Output is correct
4 Correct 27 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 110 ms 816 KB Output is partially correct
2 Partially correct 233 ms 820 KB Output is partially correct
3 Partially correct 130 ms 820 KB Output is partially correct
4 Partially correct 104 ms 820 KB Output is partially correct
5 Partially correct 124 ms 996 KB Output is partially correct
6 Partially correct 108 ms 996 KB Output is partially correct
7 Partially correct 100 ms 996 KB Output is partially correct
8 Partially correct 102 ms 996 KB Output is partially correct
9 Partially correct 95 ms 996 KB Output is partially correct
10 Partially correct 104 ms 996 KB Output is partially correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Partially correct 122 ms 996 KB Output is partially correct
2 Partially correct 133 ms 996 KB Output is partially correct
3 Partially correct 158 ms 996 KB Output is partially correct
4 Partially correct 126 ms 996 KB Output is partially correct
5 Partially correct 119 ms 996 KB Output is partially correct
6 Partially correct 129 ms 996 KB Output is partially correct
7 Partially correct 122 ms 996 KB Output is partially correct
8 Partially correct 124 ms 996 KB Output is partially correct
9 Partially correct 171 ms 996 KB Output is partially correct
10 Partially correct 119 ms 996 KB Output is partially correct
11 Partially correct 132 ms 996 KB Output is partially correct
12 Partially correct 150 ms 996 KB Output is partially correct
13 Partially correct 132 ms 996 KB Output is partially correct
14 Partially correct 116 ms 996 KB Output is partially correct
15 Partially correct 127 ms 996 KB Output is partially correct
16 Partially correct 123 ms 996 KB Output is partially correct
17 Partially correct 122 ms 996 KB Output is partially correct
18 Partially correct 136 ms 996 KB Output is partially correct
19 Partially correct 135 ms 996 KB Output is partially correct
20 Partially correct 111 ms 996 KB Output is partially correct
21 Partially correct 124 ms 996 KB Output is partially correct
22 Partially correct 138 ms 996 KB Output is partially correct
23 Partially correct 136 ms 996 KB Output is partially correct
24 Partially correct 104 ms 996 KB Output is partially correct
25 Partially correct 110 ms 996 KB Output is partially correct
26 Partially correct 122 ms 996 KB Output is partially correct
27 Partially correct 126 ms 996 KB Output is partially correct
28 Partially correct 122 ms 996 KB Output is partially correct
29 Partially correct 168 ms 996 KB Output is partially correct
30 Partially correct 153 ms 996 KB Output is partially correct
31 Partially correct 125 ms 996 KB Output is partially correct
32 Partially correct 121 ms 996 KB Output is partially correct
33 Partially correct 110 ms 996 KB Output is partially correct
34 Partially correct 142 ms 996 KB Output is partially correct
35 Partially correct 162 ms 996 KB Output is partially correct
36 Partially correct 110 ms 996 KB Output is partially correct
37 Partially correct 167 ms 996 KB Output is partially correct
38 Partially correct 153 ms 996 KB Output is partially correct
39 Partially correct 104 ms 996 KB Output is partially correct
40 Partially correct 137 ms 996 KB Output is partially correct