답안 #370106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
370106 2021-02-23T09:17:27 Z 79brue 코알라 (APIO17_koala) C++14
100 / 100
85 ms 512 KB
#include <bits/stdc++.h>
#include "koala.h"

using namespace std;

typedef long long ll;

int minValue(int n, int w){
    int A[102] = {1};
    int B[102] = {0};
    playRound(A, B);
    for(int i=0; i<n; i++){
        if(B[i] <= A[i]) return i;
    }
    exit(1);
}

int maxValue(int n, int W) {
    vector<int> candidate;
    for(int i=0; i<n; i++) candidate.push_back(i);
    while((int)candidate.size() > 1){
        int tmp = W / (int)candidate.size();
        int A[102] = {0};
        int B[102] = {0};
        for(auto cand: candidate) A[cand] = tmp;
        playRound(A, B);

        candidate.clear();
        for(int i=0; i<n; i++) if(B[i] > tmp) candidate.push_back(i);
    }
    return candidate[0];
}

int greaterValue(int N, int W) {
    int MIN = 1, MAX = 9;
    while(MIN <= MAX){
        int MID = (MIN + MAX) / 2;

        int A[102] = {MID, MID};
        int B[102] = {0};
        playRound(A, B);
        if(B[0] > MID && B[1] > MID) MIN = MID + 1;
        else if(B[0] <= MID && B[1] <= MID) MAX = MID - 1;
        else return B[0] < B[1];
    }
    exit(1);
}

void solve(int n, int *P, int l, int r, vector<int>& v){
    if(l==r){
        P[v[0]] = l+1;
        return;
    }
    int tmp = min((int)sqrt(2*(l+1)), n / (r-l+1));

    int A[102] = {0};
    int B[102] = {0};
    for(auto i: v) A[i] = tmp;
    playRound(A, B);

    vector<int> v1, v2;
    for(auto i: v){
        if(B[i] > tmp) v2.push_back(i);
        else v1.push_back(i);
    }
    solve(n, P, l, l + (int)v1.size() - 1, v1);
    solve(n, P, r - (int)v2.size() + 1, r, v2);
}

int n;
bool compare(int x, int y){
    int A[102]={0};
    int B[102]={0};
    A[x] = A[y] = n;
    playRound(A, B);
    return B[y] > n;
}

void mergeSort(int l, int r, int* arr){
    if(l==r) return;
    int m = (l+r)>>1;
    mergeSort(l, m, arr);
    mergeSort(m+1, r, arr);

    int arr2[102]={0};
    for(int i=l, j=m+1, k=l; k<=r; ){
        if(i>m) arr2[k++] = arr[j++];
        else if(j>r) arr2[k++] = arr[i++];
        else if(compare(arr[i], arr[j])) arr2[k++] = arr[i++];
        else arr2[k++] = arr[j++];
    }
    for(int i=l; i<=r; i++) arr[i] = arr2[i];
}

void allValues(int N, int W, int *P) {
    n = N;
    if(W==N){
        vector<int> vec (N);
        for(int i=0; i<N; i++) vec[i] = i;
        solve(N, P, 0, N-1, vec);
    }
    else{
        int idx[102]={0};
        for(int i=0; i<N; i++) idx[i] = i;

        mergeSort(0, n-1, idx);
        for(int i=0; i<N; i++){
            P[idx[i]] = i+1;
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 364 KB Output is correct
2 Correct 6 ms 364 KB Output is correct
3 Correct 6 ms 384 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 364 KB Output is correct
2 Correct 18 ms 364 KB Output is correct
3 Correct 18 ms 364 KB Output is correct
4 Correct 17 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 364 KB Output is correct
2 Correct 85 ms 364 KB Output is correct
3 Correct 73 ms 364 KB Output is correct
4 Correct 71 ms 364 KB Output is correct
5 Correct 74 ms 364 KB Output is correct
6 Correct 74 ms 364 KB Output is correct
7 Correct 73 ms 364 KB Output is correct
8 Correct 77 ms 412 KB Output is correct
9 Correct 74 ms 364 KB Output is correct
10 Correct 70 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 364 KB Output is correct
2 Correct 47 ms 364 KB Output is correct
3 Correct 45 ms 364 KB Output is correct
4 Correct 44 ms 492 KB Output is correct
5 Correct 43 ms 364 KB Output is correct
6 Correct 44 ms 364 KB Output is correct
7 Correct 44 ms 364 KB Output is correct
8 Correct 43 ms 364 KB Output is correct
9 Correct 43 ms 364 KB Output is correct
10 Correct 42 ms 364 KB Output is correct
11 Correct 49 ms 364 KB Output is correct
12 Correct 25 ms 364 KB Output is correct
13 Correct 44 ms 364 KB Output is correct
14 Correct 40 ms 364 KB Output is correct
15 Correct 40 ms 512 KB Output is correct
16 Correct 39 ms 364 KB Output is correct
17 Correct 38 ms 364 KB Output is correct
18 Correct 40 ms 364 KB Output is correct
19 Correct 39 ms 364 KB Output is correct
20 Correct 40 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 364 KB Output is correct
2 Correct 4 ms 364 KB Output is correct
3 Correct 5 ms 364 KB Output is correct
4 Correct 5 ms 364 KB Output is correct
5 Correct 4 ms 364 KB Output is correct
6 Correct 5 ms 364 KB Output is correct
7 Correct 5 ms 364 KB Output is correct
8 Correct 5 ms 364 KB Output is correct
9 Correct 5 ms 364 KB Output is correct
10 Correct 4 ms 364 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 364 KB Output is correct
13 Correct 5 ms 364 KB Output is correct
14 Correct 5 ms 364 KB Output is correct
15 Correct 4 ms 364 KB Output is correct
16 Correct 5 ms 364 KB Output is correct
17 Correct 5 ms 364 KB Output is correct
18 Correct 5 ms 364 KB Output is correct
19 Correct 5 ms 364 KB Output is correct
20 Correct 5 ms 364 KB Output is correct
21 Correct 5 ms 364 KB Output is correct
22 Correct 5 ms 364 KB Output is correct
23 Correct 5 ms 364 KB Output is correct
24 Correct 5 ms 364 KB Output is correct
25 Correct 5 ms 364 KB Output is correct
26 Correct 5 ms 364 KB Output is correct
27 Correct 5 ms 364 KB Output is correct
28 Correct 5 ms 364 KB Output is correct
29 Correct 5 ms 364 KB Output is correct
30 Correct 5 ms 364 KB Output is correct
31 Correct 5 ms 364 KB Output is correct
32 Correct 5 ms 364 KB Output is correct
33 Correct 5 ms 364 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 5 ms 364 KB Output is correct
37 Correct 5 ms 492 KB Output is correct
38 Correct 5 ms 364 KB Output is correct
39 Correct 5 ms 364 KB Output is correct
40 Correct 4 ms 364 KB Output is correct