제출 #393702

#제출 시각아이디문제언어결과실행 시간메모리
393702BertedGarage (IOI09_garage)C++14
100 / 100
2 ms360 KiB
#include <iostream> #include <queue> #include <assert.h> using namespace std; int N, M, A[101], B[2001]; int where[2001], filled[101], to = 0; queue<int> q; int res = 0; int main() { ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < M; i++) { where[i] = -1; cin >> B[i]; } for (int k = 0; k < 2 * M; k++) { int i; cin >> i; if (i > 0) { i--; if (to == N) {q.push(i);} else { to++; for (int j = 0; j < N; j++) { if (!filled[j]) {res += A[j] * B[i]; filled[j] = 1; where[i] = j; break;} } } } else { i = -i; i--; filled[where[i]] = 0; to--; if (q.size()) { to++; filled[where[i]] = 1; where[q.front()] = where[i]; res += A[where[i]] * B[q.front()]; q.pop(); } } } cout << res << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...