답안 #1030290

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030290 2024-07-22T02:15:56 Z vjudge1 코알라 (APIO17_koala) C++17
컴파일 오류
0 ms 0 KB
#include "koala.h"
#include<bits/stdc++.h>
using namespace std;
mt19937 rng(243987);
int you[100];
int minValue(int N, int W) {
    int me[100]{1};
    playRound(me,you);
    for(int i=0;i<N;i++)
        if(you[i]==0)
            return i;
    return 0;
}

int maxValue(int N, int W) {
    int me[100];
    vector<int>theposs(N);
    iota(theposs.begin(),theposs.end(),0);
    while(theposs.size()>1){
        memset(me,0,sizeof me);
        for(auto i:theposs)
            me[i]=W/theposs.size();
        playRound(me,you);
        vector<int>theposs2;
        for(auto i:theposs)
            if(you[i])theposs2.push_back(i);
        theposs=theposs2;
    }
    return theposs[0];
}
int greaterValue(int N, int W) {
    int me[100]{1,1};
    int L=1,R=min(W/2,8);
    while(L<=R){
        int mid=L+R>>1;
        me[0]=mid;
        me[1]=mid;
        playRound(me,you);
        if(you[0]-you[1])
            return cerr<<mid,!you[0];
        if(you[0])
            L=mid+1;
        else R=mid-1;
    }
    return 0;
}
int lst[101];
int smal[101];
int greaterValue2(int A,int B) {
    if(smal[A]^smal[B])
        return smal[A];
    if(lst[A]-lst[B])
        return lst[A]<lst[B];
    int me[100]{};
    me[A]=lst[A];me[B]=lst[B];
    playRound(me,you);
    return !you[A];
}
void allValues(int N, int W, int *P) {
    vector<int>v(N);
    iota(v.begin(),v.end(),0);
    int K=maxValue(N,W);
    vector<int>small;
    swap(v[0],v[K]);
    int me[100]{};
    me[K]=13;
    playRound(me,you);
    for(int i=0;i<N;i++)
        if(!you[i])
            small.push_back(i);
    for(auto k:small)
        smal[i]=1;
    for(int i=0;i<N;i++){
        int l=1,r=8;
        if(small[i]) {
            r=3;
        } else {
            l=3;
        }
        while(l<=r){
            int mid=l+r+1>>1;
            int me[100]{};
            me[i]=mid;
            playRound(me,you);
            if(you[i])
                lst[i]=mid,l=mid+1;
            else r=mid-1;
        }
    }
    stable_sort(v.begin()+1,v.end(),[](int a,int b){
        return !greaterValue2(a,b);
    });
    for(int i=0;i<N;i++)
        P[v[i]]=N-i;
}

Compilation message

koala.cpp: In function 'int greaterValue(int, int)':
koala.cpp:35:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |         int mid=L+R>>1;
      |                 ~^~
koala.cpp: In function 'void allValues(int, int, int*)':
koala.cpp:72:14: error: 'i' was not declared in this scope
   72 |         smal[i]=1;
      |              ^
koala.cpp:71:14: warning: unused variable 'k' [-Wunused-variable]
   71 |     for(auto k:small)
      |              ^
koala.cpp:81:24: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   81 |             int mid=l+r+1>>1;
      |                     ~~~^~