# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1089814 | vjudge1 | Garage (IOI09_garage) | C++14 | 1 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// [IOI2009] Garage
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M;
cin >> N >> M;
vector<int> R(N), W(M), P(M, -1);
for (int &r : R) cin >> r; // 停车位s每千克收费的价格
for (int &w : W) cin >> w; // 车辆k的重量
set<int> F; // 空余的停车位
for (int i = 0; i < N; i++) F.insert(i);
queue<int> Q; // 入口队列
int ans = 0;
for (int i = 0, a; i < 2 * M and cin >> a; i++) {
if (a > 0) { // 到达
--a;
if (F.empty()) { // 没有空位
Q.push(a); // 排队
} else { // 有空位
assert(Q.empty());
int p = *F.begin();
ans += R[p] * W[a], F.erase(p), P[a] = p; // a停到p处
}
} else { // 离开
a = -a - 1, F.insert(P[a]), P[a] = -1;
if (!Q.empty()) {
int b = Q.front(), p = *F.begin();
ans += R[p] * W[b], Q.pop(), F.erase(p), P[b] = p;
}
}
}
cout << ans;
return 0;
}
// AC 100
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |