# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709667 | 2023-03-14T07:07:33 Z | DarkMatter | Garage (IOI09_garage) | C++17 | 4 ms | 340 KB |
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int>pi; typedef pair<ll, ll>pl; typedef vector<pi>vpi; typedef vector<pl>vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<bool> vb; const long double PI = acos(-1); const int oo = 2e9; const int MOD = 998244353; const int N = 2e5 + 7; #define endl '\n' #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define read(v) for (auto& it : v) scanf("%d", &it); #define readL(v) for (auto& it : v) scanf("%lld", &it); #define print(v) for (auto it : v) printf("%d ", it); puts(""); #define printL(v) for (auto it : v) printf("%lld ", it); puts(""); void solve() { int n, m; scanf("%d %d", &n, &m); vl v(n), w(m); vb vis(n); readL(v); readL(w); queue<ll>q; map<int, int>mp; ll ans = 0; for (int i = 0, x; i < 2 * m; i++) { scanf("%d", &x); if (x > 0) q.push(x); else vis[mp[-x]] = false; while (!q.empty()) { int cur = q.front(); bool ok = false; for (int j = 0; j < n; j++) { if (!vis[j]) { vis[j] = ok = true, mp[cur] = j; ans += v[j] * w[cur - 1]; break; } } if (!ok) break; q.pop(); } } printf("%lld\n", ans); } int t = 1; int main() { //#ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); //#endif //scanf("%d", &t); while (t--) solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Correct | 1 ms | 304 KB | Output is correct |
4 | Correct | 1 ms | 300 KB | Output is correct |
5 | Correct | 1 ms | 300 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 308 KB | Output is correct |
16 | Correct | 2 ms | 340 KB | Output is correct |
17 | Correct | 2 ms | 312 KB | Output is correct |
18 | Correct | 2 ms | 340 KB | Output is correct |
19 | Correct | 4 ms | 340 KB | Output is correct |
20 | Correct | 2 ms | 340 KB | Output is correct |