답안 #262218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
262218 2020-08-12T13:35:00 Z BlancaHM Garage (IOI09_garage) C++14
100 / 100
1 ms 416 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstring>
#include <cmath>
#include <climits>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
typedef vector<pii> vpii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int N, M, q, prof;
	cin >> N >> M;
	int R[N], W[M], occ[N], pos[M];
	for (int i = 0; i < N; i++) {
		cin >> R[i];
		occ[i] = 0;
	}
	for (int i = 0; i < M; i++) cin >> W[i];
	prof = 0;
	bool space;
	queue<int> Q;
	for (int i = 0; i < 2*M; i++) {
		cin >> q;
		if (q < 0) {
			q = abs(q);
			if (!Q.empty()) {
				occ[pos[q-1]] = Q.front();
				pos[Q.front()-1] = pos[q-1];
				prof += W[Q.front()-1]*R[pos[Q.front()-1]];
				Q.pop();
			} else {
				occ[pos[q-1]] = 0;
			}
		} else {
			space = false;
			for (int j = 0; j < N; j++) {
				if (occ[j] == 0) {
					space = true;
					pos[q-1] = j;
					occ[j] = q;
					prof += W[q-1]*R[j];
					break;
				}
			}
			if (!space) Q.push(q);
		}
	}
	cout << prof << "\n";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 416 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct