답안 #122945

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
122945 2019-06-29T15:35:07 Z KieranHorgan Garage (IOI09_garage) C++17
100 / 100
3 ms 380 KB
#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define ll long long
// #define int long long
#define ld double
#define pii pair<int,int>
#define rand() abs((rand()<<15)|rand())
#define randll() abs(((long long)rand()<<30)|rand())
const int MOD = 1000000007;

int r[105];
int w[2005];
int taken[105];
int hasTaken[2005];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		cin >> r[i];

	for(int i = 1; i <= m; i++)
		cin >> w[i];

	queue<int> q;

	int ans = 0;
	for(int t = 0; t < 2*m; t++) {
		int i;
		cin >> i;
		if(i > 0) {
			q.push(i);

			int j = q.front();
			for(int i = 1; i <= n; i++)
				if(!taken[i]) {
					taken[i] = 1;
					hasTaken[j] = i;
					ans += r[i] * w[j];
					q.pop();
					break;
				}
		} else {
			i *= -1;
			taken[hasTaken[i]] = 0;
			hasTaken[i] = 0;
			if(!q.empty()) {
				int j = q.front();
				for(int i = 1; i <= n; i++)
					if(!taken[i]) {
						taken[i] = 1;
						hasTaken[j] = i;
						ans += r[i] * w[j];
						q.pop();
						break;
					}
			}
		}
	}
	cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct