# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
761225 | Blagoj | Garage (IOI09_garage) | C++17 | 2 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()
int main() {
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
int n, m, t;
cin >> n >> m;
t = n;
int r[n], w[m], went[m];
for (int i = 0; i < n; i++) cin >> r[i];
for (int i = 0; i < m; i++) cin >> w[i];
queue<int> q;
bool full[n];
memset(full, 0, sizeof(full));
ll ans = 0;
for (int i = 0; i < 2 * m; i++) {
int c;
cin >> c;
if (c > 0) {
c--;
if (n == 0) {
q.push(c);
continue;
}
for (int j = 0; j < t; j++) {
if (full[j]) continue;
ans += w[c] * r[j];
full[j] = 1;
went[c] = j;
n--;
break;
}
}
else {
c *= -1;
c--;
n++;
full[went[c]] = 0;
while (n > 0 && q.size() > 0) {
int f = q.front();
q.pop();
for (int j = 0; j < t; j++) {
if (full[j]) continue;
ans += w[f] * r[j];
full[j] = 1;
went[f] = j;
n--;
break;
}
}
}
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |