# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1055646 | Braulinho | Garage (IOI09_garage) | C++14 | 0 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.setf(ios::fixed);
cout.precision(10);
ll N, M;
cin >> N >> M;
vector<ll> rates(N + 1);
vector<ll> weights(M + 1);
vector<ll> parking(N + 1, 0);
queue<ll> waitingQueue;
for (int i = 1; i <= N; ++i) {
cin >> rates[i];
}
for (int i = 1; i <= M; ++i) {
cin >> weights[i];
}
stack<ll> freeSpaces;
for (int i = N; i >= 1; --i) {
freeSpaces.push(i);
}
ll totalRevenue = 0;
for (int i = 0; i < 2 * M; ++i) {
int car;
cin >> car;
if (car > 0) {
if (!freeSpaces.empty()) {
int space = freeSpaces.top();
freeSpaces.pop();
parking[space] = car;
totalRevenue += weights[car] * rates[space];
} else {
waitingQueue.push(car);
}
} else {
car = -car;
ll space = 0;
for (int j = 1; j <= N; ++j) {
if (parking[j] == car) {
space = j;
break;
}
}
parking[space] = 0;
freeSpaces.push(space);
if (!waitingQueue.empty()) {
ll nextCar = waitingQueue.front();
waitingQueue.pop();
freeSpaces.pop();
parking[space] = nextCar;
totalRevenue += weights[nextCar] * rates[space];
}
}
}
cout << totalRevenue << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |