답안 #309472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
309472 2020-10-03T14:17:01 Z cig32 Garage (IOI09_garage) C++14
100 / 100
4 ms 384 KB
#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;
}

Compilation message

garage.cpp: In function 'int bS(bool*, int)':
garage.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
   17 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 3 ms 384 KB Output is correct
20 Correct 4 ms 328 KB Output is correct