# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
986728 | lyu | Garage (IOI09_garage) | C++17 | 2 ms | 500 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
int parking[n];
for(int i = 0; i < n; i++) cin >> parking[i];
int weight[m];
for(int i = 0; i < m; i++) cin >> weight[i];
int status, profit = 0;
unordered_map<int, int> cars;
unordered_map<int, int> taken;
queue<int> waiting;
for(int i = 0; i < 2*m; i++) {
cin >> status;
if(status > 0) {
status--;
bool parked = false;
for(int i = 0; i < n; i++) {
if(taken.count(i) == 0) {
taken[i] = status;
cars[status] = i;
profit += parking[i] * weight[status];
parked = true;
break;
}
}
if(!parked) waiting.push(status);
}
else {
status++;
status *= -1;
int num = cars[status];
cars.erase(status);
taken.erase(num);
if(!waiting.empty()) {
int f = waiting.front();
cars[f] = num;
taken[num] = f;
profit += weight[f] * parking[num];
waiting.pop();
}
}
}
cout << profit << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |