답안 #871742

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871742 2023-11-11T12:20:21 Z Matjaz 최후의 만찬 (IOI12_supper) C++14
컴파일 오류
0 ms 0 KB
#include "advisor.h"

#include<set>
#include<queue>
#include<vector>

using namespace std;

void ComputeAdvice(int *C, int N, int K, int M) {
    
    set<int> scafold;
    for (int i=0;i<K;i++) scafold.insert(i);
    
    vector<queue<int> > Q(N);
    vector<queue<int> > returns(N);
    vector<int> takeback(N, -1);

    for (int i=0;i<N;i++) Q[C[i]].push(i);
    for (int i=0;i<N;i++) Q[i].push(N);

    priority_queue<pair<int,int> > next_use;
    for (int i=0;i<K;i++) next_use.push(make_pair(Q[i].front(), i));

    
    for (int i=0;i<N;i++){
        Q[C[i]].pop();
        if (scafold.count(C[i]) > 0) {
            next_use.push(make_pair(Q[C[i]].front(), C[i]));
            continue;
        }
            
        while (true){
            if (scafold.count(next_use.top().second) == 0){
                next_use.pop();
                continue;
            }
            assert(next_use.top().first > i);
            break;
        }

        int bestcolour = next_use.top().second;
        next_use.pop();

        scafold.erase(bestcolour);
        scafold.insert(C[i]);
        next_use.push(make_pair(Q[C[i]].front(),C[i]));
        returns[bestcolour].push(i);
        takeback[i] = bestcolour;
    }

    Q.assign(N, queue<int> ());
    for (int i=0;i<N;i++) Q[C[i]].push(i);
    for (int i=0;i<N;i++) Q[i].push(N);

    for (int i=0;i<K;i++){
        if (Q[i].empty()){
            WriteAdvice(0);
            continue;
        }
        
        if (returns[i].empty()){
            WriteAdvice(1);
            continue;
        }
            
        if (Q[i].front() <= returns[i].front()){
            WriteAdvice(1);
        } else WriteAdvice(0);

    }
    
        
    for (int i=0;i<N;i++){
        Q[C[i]].pop();
        if (Q[C[i]].empty()){
            WriteAdvice(0);
            continue;
        }
        if (returns[C[i]].empty()){
            WriteAdvice(1);
            continue;
        }

        if (Q[C[i]].front() <= returns[C[i]].front()){
            WriteAdvice(1);
        } else WriteAdvice(0);

        if (takeback[i] != -1) returns[takeback[i]].pop();
    }
    
}
#include "assistant.h"


#include<queue>
#include<set>
#include<assert.h>

using namespace std;




void Assist(unsigned char *A, int N, int K, int R) {
    
    set<int> expendable,scafold;
    for (int i=0;i<K;i++) if (A[i] == 0) expendable.insert(i);
    for (int i=0;i<K;i++) scafold.insert(i);
    
    for (int i=0;i<N;i++){
        int req = GetRequest();
        
        if (scafold.count(req) > 0){
            if (A[K + i] == 0) expendable.insert(req);
            continue;
        }
        assert(expendable.size() > 0);
        PutBack(*expendable.begin());
        scafold.erase(*expendable.begin());
        expendable.erase(*expendable.begin());
        scafold.insert(req);
        if (A[K + i] == 0) expendable.insert(req);
    }
}

Compilation message

advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:38:13: error: 'assert' was not declared in this scope
   38 |             assert(next_use.top().first > i);
      |             ^~~~~~
advisor.cpp:6:1: note: 'assert' is defined in header '<cassert>'; did you forget to '#include <cassert>'?
    5 | #include<queue>
  +++ |+#include <cassert>
    6 | #include<vector>