답안 #108364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108364 2019-04-28T18:27:32 Z RezwanArefin01 코알라 (APIO17_koala) C++17
85 / 100
113 ms 512 KB
#include <bits/stdc++.h>
#include "koala.h"
using namespace std; 

int B[100], R[100], N, W;  

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

int maxValue(int N, int W) {
    vector<int> L; 
    for(int i = 0; i < N; ++i)
        L.push_back(i); 
    while(L.size() > 1) {
        int t = W / L.size(); 
        for(int i = 0; i < N; ++i) 
            B[i] = R[i] = 0; 
        for(int i : L) B[i] = t; 
        playRound(B, R); 
        L.clear(); 
        for(int i = 0; i < N; ++i) {
            if(R[i] > t) {
                L.push_back(i); 
            }
        }
    }
    return L[0];
}

bool compare(int i, int j) {
    int lo = 1, hi = min(W / 2, 9); 
    for(int i = 0; i < N; ++i) B[i] = 0;  
    while(lo <= hi) {
        int mid = lo + hi >> 1; 
        B[i] = B[j] = mid; 
        playRound(B, R); 
        bool z = R[i] > B[i]; 
        bool o = R[j] > B[j]; 
        if(z == o) {
            if(z) lo = mid + 1; 
            else hi = mid - 1; 
        } else {
            return z ? 0 : 1; 
        }
    }  
}

int greaterValue(int _N, int _W) {
    N = _N; W = _W;
    return compare(0, 1); 
}

int Q[100]; 

void sort(vector<int> &a, int l, int r) {
    if(l == r) {
        Q[l] = a[0]; 
        return; 
    }
    int t = W / a.size(); 
    memset(B, 0, sizeof B); 
    for(int i : a) B[i] = t; 
    playRound(B, R); 

    vector<int> big, small; 
    for(int i : a) {
        if(R[i] > t) big.push_back(i); 
        else small.push_back(i); 
    }
    if(big == a || small == a) {
        sort(a.begin(), a.end(), compare); 
        for(int i = l; i <= r; i++) {
            Q[i] = a[i - l]; 
        }
        return; 
    }
    sort(small, l, l + small.size() - 1); 
    sort(big, r - big.size() + 1, r); 
}

void allValues(int _N, int _W, int *P) {
    N = _N, W = _W; 
    vector<int> v; 
    for(int i = 0; i < N; ++i) 
        v.push_back(i); 
    sort(v, 0, N - 1); 
    for(int i = 0; i < N; ++i) 
        P[Q[i]] = i + 1; 
}

Compilation message

koala.cpp: In function 'bool compare(int, int)':
koala.cpp:39:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = lo + hi >> 1; 
                   ~~~^~~~
koala.cpp:51:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 8 ms 512 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 384 KB Output is correct
2 Correct 14 ms 384 KB Output is correct
3 Correct 15 ms 384 KB Output is correct
4 Correct 22 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 384 KB Output is correct
2 Correct 113 ms 432 KB Output is correct
3 Correct 66 ms 384 KB Output is correct
4 Correct 57 ms 384 KB Output is correct
5 Correct 51 ms 384 KB Output is correct
6 Correct 59 ms 384 KB Output is correct
7 Correct 52 ms 384 KB Output is correct
8 Correct 57 ms 504 KB Output is correct
9 Correct 81 ms 384 KB Output is correct
10 Correct 57 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 8 ms 384 KB Output is correct
3 Correct 8 ms 384 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 8 ms 384 KB Output is correct
6 Correct 31 ms 384 KB Output is correct
7 Correct 7 ms 384 KB Output is correct
8 Correct 11 ms 384 KB Output is correct
9 Correct 7 ms 384 KB Output is correct
10 Correct 8 ms 384 KB Output is correct
11 Correct 8 ms 384 KB Output is correct
12 Correct 7 ms 384 KB Output is correct
13 Correct 7 ms 300 KB Output is correct
14 Correct 8 ms 384 KB Output is correct
15 Correct 9 ms 384 KB Output is correct
16 Correct 9 ms 384 KB Output is correct
17 Correct 9 ms 364 KB Output is correct
18 Correct 9 ms 384 KB Output is correct
19 Correct 9 ms 384 KB Output is correct
20 Correct 7 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 9 ms 384 KB Output is partially correct
2 Partially correct 10 ms 512 KB Output is partially correct
3 Partially correct 12 ms 384 KB Output is partially correct
4 Partially correct 13 ms 384 KB Output is partially correct
5 Partially correct 11 ms 384 KB Output is partially correct
6 Partially correct 11 ms 384 KB Output is partially correct
7 Partially correct 13 ms 384 KB Output is partially correct
8 Partially correct 11 ms 384 KB Output is partially correct
9 Partially correct 11 ms 384 KB Output is partially correct
10 Partially correct 12 ms 384 KB Output is partially correct
11 Partially correct 10 ms 384 KB Output is partially correct
12 Partially correct 10 ms 384 KB Output is partially correct
13 Partially correct 11 ms 396 KB Output is partially correct
14 Partially correct 10 ms 384 KB Output is partially correct
15 Partially correct 11 ms 384 KB Output is partially correct
16 Partially correct 10 ms 404 KB Output is partially correct
17 Partially correct 10 ms 384 KB Output is partially correct
18 Partially correct 10 ms 384 KB Output is partially correct
19 Partially correct 11 ms 384 KB Output is partially correct
20 Partially correct 12 ms 384 KB Output is partially correct
21 Partially correct 10 ms 384 KB Output is partially correct
22 Partially correct 15 ms 384 KB Output is partially correct
23 Partially correct 10 ms 384 KB Output is partially correct
24 Partially correct 10 ms 384 KB Output is partially correct
25 Partially correct 10 ms 384 KB Output is partially correct
26 Partially correct 10 ms 384 KB Output is partially correct
27 Partially correct 9 ms 432 KB Output is partially correct
28 Partially correct 10 ms 384 KB Output is partially correct
29 Partially correct 11 ms 384 KB Output is partially correct
30 Partially correct 11 ms 384 KB Output is partially correct
31 Partially correct 11 ms 384 KB Output is partially correct
32 Partially correct 11 ms 384 KB Output is partially correct
33 Partially correct 17 ms 384 KB Output is partially correct
34 Partially correct 13 ms 384 KB Output is partially correct
35 Partially correct 10 ms 384 KB Output is partially correct
36 Partially correct 11 ms 384 KB Output is partially correct
37 Partially correct 23 ms 404 KB Output is partially correct
38 Partially correct 11 ms 384 KB Output is partially correct
39 Partially correct 11 ms 384 KB Output is partially correct
40 Partially correct 13 ms 384 KB Output is partially correct