Submission #1089814

# Submission time Handle Problem Language Result Execution time Memory
1089814 2024-09-17T08:01:50 Z vjudge1 Garage (IOI09_garage) C++14
100 / 100
1 ms 348 KB
// [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
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct