답안 #988837

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
988837 2024-05-26T12:35:11 Z lalig777 최후의 만찬 (IOI12_supper) C++14
컴파일 오류
0 ms 0 KB
#include "advisor.h"
#include <iostream>
#include <vector>
#include <unordered_set>
#include <queue>
using namespace std;

void ComputeAdvice(vector<int>C, int N, int K, int M){
    int digits;
    for (int i=0; i<21; i++){
        if ((1<<i)>=N-1){
            digits=i;
            break;
        }
    }
    if (K==1) return;
    unordered_set<int>current;
    priority_queue<pair<int,int>>next;
    vector<queue<int>>orden(N);
    for (int i=0; i<N; i++){
        int x=C[i];
        if (x<K){
            if (!(current.find(x)!=current.end())){
                next.push(make_pair(i, x));
                current.insert(x);
            }
        }orden[x].push(i);
    }for (int i=0; i<K; i++){
        if (!(current.find(i)!=current.end())){
            next.push(make_pair(1e9, i));
            current.insert(i);
        }
    }
    for (int i=0; i<N; i++){
        int x=C[i];
        orden[x].pop();
        int pos;
        if (orden[x].empty()) pos=1e9;
        else pos=orden[x].front();
        if (!(current.find(x)!=current.end())){
            current.insert(x);
            int remov=next.top().second;
            next.pop();
            current.erase(remov);
            for (int j=digits-1; j>=0; j--){
                int y=1<<j;
                if (remov>=y){
                    remov-=y;
                    WriteAdvice('1');
                }else WriteAdvice('0');
            }
        }
        next.push(make_pair(pos, x));
    }return;
}
#include "assistant.h"
#include <iostream>
#include <vector>
#include <unordered_set>
#include <queue>
using namespace std;

void Assist(vector<unsigned char>A, int N, int K, int R){
    if (K==1){
        int now=0;
        for (int i=0; i<N; i++){
            int follow=GetRequest();
            if (follow!=now){
                PutBack(now);
                now=follow;
            }
        }return;
    }
    int digits, count=0;
    for (int i=0; i<21; i++){
        if ((1<<i)>=N){
            digits=i;
            break;
        }
    }
    unordered_set<int>current;
    for (int i=0; i<K; i++) current.insert(i);
    for (int i=0; i<N; i++){
        int follow=GetRequest();
        if (!(current.find(follow)!=current.end())){
            int remov=0;
            for (int j=0; j<digits; j++){
                if (A[j+count*digits]=='1') remov+=(1<<(digits-j-1));
            }count++;
            PutBack(remov);
            current.erase(remov);
            current.insert(follow);
        }
    }
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(std::vector<int>, int, int, int)':
advisor.cpp:45:22: warning: 'digits' may be used uninitialized in this function [-Wmaybe-uninitialized]
   45 |             for (int j=digits-1; j>=0; j--){
      |                      ^
/usr/bin/ld: /tmp/ccFFKxvY.o: in function `main':
advisor_grader.cpp:(.text.startup+0xe6): undefined reference to `ComputeAdvice(int*, int, int, int)'
collect2: error: ld returned 1 exit status

assistant.cpp: In function 'void Assist(std::vector<unsigned char>, int, int, int)':
assistant.cpp:33:30: warning: 'digits' may be used uninitialized in this function [-Wmaybe-uninitialized]
   33 |                 if (A[j+count*digits]=='1') remov+=(1<<(digits-j-1));
      |                         ~~~~~^~~~~~~
/usr/bin/ld: /tmp/cc9E2UhM.o: in function `main':
assistant_grader.cpp:(.text.startup+0x21e): undefined reference to `Assist(unsigned char*, int, int, int)'
collect2: error: ld returned 1 exit status