제출 #309472

#제출 시각아이디문제언어결과실행 시간메모리
309472cig32Garage (IOI09_garage)C++14
100 / 100
4 ms384 KiB
#include <bits/stdc++.h>
using namespace std;
bool tiAs(bool available[], int N){
    for(int i=0;i<N;i++){
        if(available[i]==true){
            return true;
        }
    }
    return false;
}
int bS(bool available[], int N){
    for(int i=0;i<N;i++){
        if(available[i]==true){
            return i;
        }
    }
}
int main(){
    int N,M;
    cin >> N >> M;
    int r[N],w[M];
    bool available[N];
    int space[M];
    for(int i=0;i<N;i++){
        cin >> r[i];
        available[i]=true;
    }
    for(int i=0;i<M;i++){
        cin >> w[i];
    }
    int ans=0;
    queue<int> waiting;
    for(int i=0;i<2*M;i++){
        int input;
        cin >> input;
        if(input>0){
            if(tiAs(available,N)==true){
                int t=bS(available,N);
                available[t]=false;
                space[input-1]=t;
                int a=w[input-1]*r[t];
                ans+=a;
            }
            else{
                waiting.push(input);
            }
        }
        else{
            available[space[abs(input)-1]]=true;
            if(waiting.size()!=0){
                available[space[abs(input)-1]]=false;
                space[waiting.front()-1]=space[abs(input)-1];
                int a=w[waiting.front()-1]*r[space[abs(input)-1]];
                waiting.pop();
                ans+=a;
            }
        }
    }
    cout << ans;
}

컴파일 시 표준 에러 (stderr) 메시지

garage.cpp: In function 'int bS(bool*, int)':
garage.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
   17 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...