답안 #403191

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403191 2021-05-12T22:27:27 Z A_D 코알라 (APIO17_koala) C++14
76 / 100
63 ms 428 KB
#include "koala.h"


#include <bits/stdc++.h>

using namespace std;
int t;
int minValue(int N, int W) {
    int ans=0;
    int B[N];
    int R[N];
    memset(B,0,sizeof(B));
    memset(R,0,sizeof(R));
    B[0]=1;
    playRound(B,R);
    for(int i=1;i<N;i++)if(R[i]==0)ans=i;
    return ans;
}

int maxValue(int N, int W) {
    int l=1,r=13,ans;
    int B[N];
    int R[N];
    bool me[N];
    int cnt=1;
    memset(B,0,sizeof(B));
    memset(me,1,sizeof(me));
    while(1){
        memset(B,0,sizeof(B));
        for(int i=0;i<N;i++){
            if(me[i]){
                B[i]=cnt;
            }
        }
        playRound(B, R);
        int u=0;
        for(int i=0;i<N;i++){
            if(me[i]&&R[i]>cnt){
                u++;
                me[i]=1;
            }
            else me[i]=0;
        }
        cnt=W/u;
        cnt=min(cnt,13);
        if(u==1){
            for(int i=0;i<N;i++){
                if(me[i])return i;
            }
        }
    }
}

int greaterValue(int N, int W) {
    int l=1,r=13,ans;
    int B[N];
    int R[N];
    memset(B,0,sizeof(B));
    while(l<=r){
        int mid=(l+r)/2;
        B[0]=mid;
        B[1]=mid;
        playRound(B, R);
        int a=R[0]>mid;
        int b=R[1]>mid;
        if(a>b)return 0;
        if(b>a)return 1;
        if(a){
            l=mid+1;
        }
        else r=mid-1;
    }
    assert(0);
}
bool com(int a,int b)
{
    int l=1,r=13,ans;
    int B[100];
    int R[100];
    while(l<=r){
        memset(B,0,sizeof(B));
        int mid=(l+r)/2;
        B[a]=mid;
        B[b]=mid;
        playRound(B, R);
        int u=R[a]>mid;
        int v=R[b]>mid;
        if(u>v)return 0;
        if(v>u)return 1;
        if(u){
            l=mid+1;
        }
        else r=mid-1;
    }
    assert(0);
}
bool com2(int a,int b)
{
    int l=1,r=113,ans;
    int B[100];
    int R[100];
    while(l<=r){
        memset(B,0,sizeof(B));
        int mid=(l+r)/2;
        B[a]=mid;
        B[b]=mid;
        t++;
        if(t==701)assert(0);
        playRound(B, R);
        int u=R[a]>mid;
        int v=R[b]>mid;
        if(u>v)return 0;
        if(v>u)return 1;
        if(u){
            l=mid+1;
        }
        else r=mid-1;
    }
    assert(0);
}
void allValues(int N, int W, int *P) {
    if (W == 2*N) {
        t=0;
        int a[N];
        for(int i=0;i<N;i++)a[i]=i;
        vector<int> vec[N*3];
        int ann=0;
        int B[N];
        int R[N];
        memset(B,0,sizeof(B));
        memset(R,0,sizeof(R));
        B[0]=1+100;
        t++;
        playRound(B,R);
        for(int i=1;i<N;i++)if(R[i]==0)ann=i;
        vec[101].push_back(ann);
        for(int i=0;i<N;i++){
            if(i==ann)continue;
            int l=102,r=113,ans=101;
            while(l<=r){
                memset(B,0,sizeof(B));
                int mid=(l+r)/2;
                B[i]=mid;
                t++;
                if(t==701)assert(0);
                playRound(B,R);

                if(R[i]>mid){
                    l=mid+1;
                    ans=mid;
                }
                else{
                    r=mid-1;
                }
            }
            vec[ans].push_back(i);
        }
        int l=0,cnt=0;
        for(int i=1;i<=200;i++){
            for(auto x:vec[i]){
                a[cnt++]=x;
            }
            if(abs(cnt-l)>1)sort(a+l,a+cnt,com2);
            l=cnt;
        }
        for(int i=0;i<N;i++){
            P[a[i]]=i+1;
        }
    }
    else {
        int a[N];
        for(int i=0;i<N;i++)a[i]=i;
        vector<int> vec[N*3];
        int ann=0;
        int B[N];
        int R[N];
        memset(B,0,sizeof(B));
        memset(R,0,sizeof(R));
        B[0]=1;
        playRound(B,R);
        for(int i=1;i<N;i++)if(R[i]==0)ann=i;
        vec[1].push_back(ann);
        for(int i=0;i<N;i++){
            if(i==ann)continue;
            int l=2,r=13,ans=1;
            while(l<=r){
                memset(B,0,sizeof(B));
                int mid=(l+r)/2;
                B[i]=mid;
                playRound(B,R);

                if(R[i]>mid){
                    l=mid+1;
                    ans=mid;
                }
                else{
                    r=mid-1;
                }
            }
            vec[ans].push_back(i);
        }
        int l=0,cnt=0;
        for(int i=1;i<14;i++){
            for(auto x:vec[i]){
                a[cnt++]=x;
            }
            if(abs(cnt-l)>1)sort(a+l,a+cnt,com);
            l=cnt;
        }
        for(int i=0;i<N;i++){
            P[a[i]]=i+1;
        }
    }
}
/*
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
*/

Compilation message

koala.cpp: In function 'int maxValue(int, int)':
koala.cpp:21:9: warning: unused variable 'l' [-Wunused-variable]
   21 |     int l=1,r=13,ans;
      |         ^
koala.cpp:21:13: warning: unused variable 'r' [-Wunused-variable]
   21 |     int l=1,r=13,ans;
      |             ^
koala.cpp:21:18: warning: unused variable 'ans' [-Wunused-variable]
   21 |     int l=1,r=13,ans;
      |                  ^~~
koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:55:18: warning: unused variable 'ans' [-Wunused-variable]
   55 |     int l=1,r=13,ans;
      |                  ^~~
koala.cpp: In function 'bool com(int, int)':
koala.cpp:77:18: warning: unused variable 'ans' [-Wunused-variable]
   77 |     int l=1,r=13,ans;
      |                  ^~~
koala.cpp: In function 'bool com2(int, int)':
koala.cpp:99:19: warning: unused variable 'ans' [-Wunused-variable]
   99 |     int l=1,r=113,ans;
      |                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 200 KB Output is correct
2 Correct 5 ms 200 KB Output is correct
3 Correct 5 ms 312 KB Output is correct
4 Correct 5 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 200 KB Output is correct
2 Correct 15 ms 308 KB Output is correct
3 Correct 19 ms 200 KB Output is correct
4 Correct 15 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 320 KB Output is correct
2 Correct 56 ms 316 KB Output is correct
3 Correct 51 ms 428 KB Output is correct
4 Correct 50 ms 312 KB Output is correct
5 Correct 63 ms 348 KB Output is correct
6 Correct 53 ms 308 KB Output is correct
7 Correct 50 ms 200 KB Output is correct
8 Correct 50 ms 328 KB Output is correct
9 Correct 52 ms 328 KB Output is correct
10 Correct 50 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 200 KB Output is correct
2 Correct 53 ms 200 KB Output is correct
3 Correct 45 ms 296 KB Output is correct
4 Correct 42 ms 288 KB Output is correct
5 Correct 46 ms 200 KB Output is correct
6 Correct 43 ms 200 KB Output is correct
7 Correct 43 ms 200 KB Output is correct
8 Correct 52 ms 200 KB Output is correct
9 Correct 43 ms 200 KB Output is correct
10 Correct 42 ms 200 KB Output is correct
11 Correct 43 ms 200 KB Output is correct
12 Correct 30 ms 200 KB Output is correct
13 Correct 43 ms 304 KB Output is correct
14 Correct 49 ms 200 KB Output is correct
15 Correct 50 ms 200 KB Output is correct
16 Correct 44 ms 200 KB Output is correct
17 Correct 42 ms 200 KB Output is correct
18 Correct 42 ms 296 KB Output is correct
19 Correct 43 ms 200 KB Output is correct
20 Correct 40 ms 200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Partially correct 21 ms 200 KB Output is partially correct
2 Partially correct 26 ms 200 KB Output is partially correct
3 Partially correct 26 ms 200 KB Output is partially correct
4 Partially correct 27 ms 200 KB Output is partially correct
5 Partially correct 25 ms 200 KB Output is partially correct
6 Partially correct 27 ms 312 KB Output is partially correct
7 Partially correct 25 ms 300 KB Output is partially correct
8 Partially correct 25 ms 308 KB Output is partially correct
9 Partially correct 27 ms 300 KB Output is partially correct
10 Partially correct 27 ms 200 KB Output is partially correct
11 Partially correct 25 ms 200 KB Output is partially correct
12 Partially correct 16 ms 200 KB Output is partially correct
13 Partially correct 26 ms 200 KB Output is partially correct
14 Partially correct 25 ms 308 KB Output is partially correct
15 Partially correct 26 ms 316 KB Output is partially correct
16 Partially correct 26 ms 312 KB Output is partially correct
17 Partially correct 25 ms 312 KB Output is partially correct
18 Partially correct 26 ms 200 KB Output is partially correct
19 Partially correct 29 ms 304 KB Output is partially correct
20 Partially correct 30 ms 312 KB Output is partially correct
21 Partially correct 30 ms 316 KB Output is partially correct
22 Partially correct 26 ms 200 KB Output is partially correct
23 Partially correct 24 ms 308 KB Output is partially correct
24 Partially correct 25 ms 288 KB Output is partially correct
25 Partially correct 27 ms 304 KB Output is partially correct
26 Partially correct 27 ms 328 KB Output is partially correct
27 Partially correct 25 ms 200 KB Output is partially correct
28 Partially correct 26 ms 308 KB Output is partially correct
29 Partially correct 25 ms 200 KB Output is partially correct
30 Partially correct 26 ms 308 KB Output is partially correct
31 Partially correct 26 ms 200 KB Output is partially correct
32 Partially correct 25 ms 200 KB Output is partially correct
33 Partially correct 25 ms 312 KB Output is partially correct
34 Partially correct 24 ms 200 KB Output is partially correct
35 Partially correct 32 ms 292 KB Output is partially correct
36 Partially correct 25 ms 308 KB Output is partially correct
37 Partially correct 25 ms 304 KB Output is partially correct
38 Partially correct 25 ms 200 KB Output is partially correct
39 Partially correct 25 ms 308 KB Output is partially correct
40 Partially correct 25 ms 292 KB Output is partially correct