# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
870140 | 2023-11-07T03:39:59 Z | inawah | Garage (IOI09_garage) | C++14 | 1 ms | 600 KB |
#include <cstdio> #include <queue> using namespace std; #define MAXN 105 #define MAXM 2005 int r[MAXN], w[MAXM], p[MAXM]; queue<int> q; bool vis[MAXN]; int main() { int N, M; scanf("%d %d\n", &N, &M); for (int i = 1; i <= N; ++i) { scanf("%d\n", &r[i]); } for (int i = 1; i <= M; ++i) { scanf("%d\n", &w[i]); } int ans = 0; for (int i = 1; i <= 2*M; ++i) { int a; scanf("%d\n", &a); if (a > 0) { int j; for (j = 1; j <= N && vis[j]; ++j); if (j <= N) { vis[j] = true; p[a] = j; } else { q.push(a); } } else { vis[p[-a]] = false; if (!q.empty()) { int f = q.front(); p[f] = p[-a]; vis[p[f]] = true; q.pop(); } ans += w[-a]*r[p[-a]]; } } printf("%d\n", ans); return 0; }
Compilation message
# | 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 | 0 ms | 344 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 | 436 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 428 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 600 KB | Output is correct |
13 | Correct | 0 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 0 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 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 | 348 KB | Output is correct |
20 | Correct | 1 ms | 440 KB | Output is correct |