답안 #108362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108362 2019-04-28T18:12:56 Z RezwanArefin01 코알라 (APIO17_koala) C++17
19 / 100
19 ms 392 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] = R[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 o ? 1 : 0; 
        }
    }  
}

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

void allValues(int N, int W, int *P) {

}

Compilation message

koala.cpp: In function 'bool compare(int, int)':
koala.cpp:40:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = lo + hi >> 1; 
                   ~~~^~~~
koala.cpp:52:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 384 KB Output is correct
2 Correct 19 ms 384 KB Output is correct
3 Correct 15 ms 392 KB Output is correct
4 Correct 15 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -