# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440813 | dynam1c | Garage (IOI09_garage) | C++17 | 2 ms | 332 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.
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define all(c) (c).begin(),(c).end()
// when you ponder, divide and conquer
signed main() {
// freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
std::ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> rr(n), ww(m), pp(m);
for (int i = 0; i < n; i++)
cin >> rr[i];
for (int i = 0; i < m; i++)
cin >> ww[i];
vector<bool> park(n), inq(m);
queue<int> q;
ll res = 0;
for (int qq = 0; qq < 2*m; qq++) {
int e;
cin >> e;
if (e > 0) {
e--;
bool parked = false;
for (int i = 0; i < n; i++)
if (!park[i]) {
parked = true;
res += rr[i] * ww[e];
pp[e] = i;
park[i] = true;
break;
}
if (!parked)
q.push(e), inq[e] = true;
} else {
e = -e - 1;
inq[e] = false;
park[pp[e]] = false;
while (!q.empty() and !inq[q.front()]) q.pop();
if (!q.empty()) {
int x = q.front(); q.pop();
park[pp[e]] = true;
res += rr[pp[e]] * ww[x];
pp[x] = pp[e];
}
}
}
cout << res << endl;
}
/* --- PSolving ---
* Simplifying (getting rid of variables, conditions, code logic, etc.)
* Reframing
* Solving a subtask (subgoal, aux. problem, removing a condition or fixing a parameter, etc.)
* Inducing
* Divide and conquer
* Working backwards
* Visual intuition
* !! Reductions don't have to be specializations, they can be generalizations
*/
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |