# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1089813 | vjudge1 | Garage (IOI09_garage) | C++14 | 1 ms | 604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// [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(N);
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;
}
// ❓❓ 0
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |