답안 #632235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
632235 2022-08-19T18:17:23 Z device Garage (IOI09_garage) C++17
100 / 100
2 ms 340 KB
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,ans = 0; cin >> n >> m;
	int space[n+1], car[m+1], curs[n+1] = {0}, curc[m+1] = {0}, available = n;
	queue<int> q;
	for(int i = 1; i <= n; i++) cin >> space[i];
	for(int i = 1; i <= m; i++) cin >> car[i];
	for(int i = 1; i <= 2*m; i++){
	    int cmd; cin >> cmd;
	    if(cmd > 0){
	        int ptr = 1;
	        while(curs[ptr] != 0 && ptr < n) ptr++;
	        if(ptr == n){
	            q.push(cmd);
	        }else{
	            curc[cmd] = ptr;
	            curs[ptr] = cmd;
	            ans += car[cmd] * space[ptr];
	            available--;
	        }
	    }else{
	        curs[curc[cmd*-1]] = 0;
	        curc[cmd*-1] = 0;
	        available++;
	    }
	    while(!q.empty()){
	        if(available == 0) break;
	        int ptr = 1;
	        while(curs[ptr] != 0 && ptr < n) ptr++;
	        curc[q.front()] = ptr;
	        curs[ptr] = q.front();
	        ans += car[q.front()] * space[ptr];
	        available--;
	        q.pop();
	    }
	}
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct