# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
440813 | dynam1c | Garage (IOI09_garage) | C++17 | 2 ms | 332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#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... |