Submission #964229

# Submission time Handle Problem Language Result Execution time Memory
964229 2024-04-16T13:05:31 Z anango Garage (IOI09_garage) C++17
100 / 100
4 ms 500 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
	int n,m;
	cin >> n >> m;
	int total = 0;
	vector<int> rates(n);
	vector<int> parkedposcar(n,-1);
	vector<int> parkedcarpos(m,-1);
	vector<int> weights(m);
	set<int> available;
	
	for (int i=0; i<n; i++) {
		available.insert(i);
	}
	for (int i=0; i<n; i++) {
		int x;
		cin >> x;
		rates[i] = x;
	}
	for (int i=0; i<m; i++) {
		int x;
		cin >> x;
		weights[i] = x;
	}
	deque<int> Q;
	for (int e=0; e<2*m; e++) {
	//	cout << "doing" <<" " << e << " " << parkedcarpos[2] << " " << parkedcarpos[0] << endl;
		//cout << "queue" <<" ";
		int x;
		for (auto i:Q) {
	//		cout << i <<" ";
		}
	//	cout << endl;
		cin >> x;
		if (x>0) {
			x--;
			if (!available.size()) {
				
				Q.push_front(x);
				
			}
			else {
				int minpos = *available.begin();
				available.erase(minpos);
				parkedcarpos[x] = minpos;
				parkedposcar[minpos] = x;
				total+=rates[minpos]*weights[x];
			}
		}
		else {
			x=-x;
			x--;
			assert(parkedcarpos[x]!=-1);
			available.insert(parkedcarpos[x]);
			parkedcarpos[x] = -1;
			while (Q.size() && available.size()) {
				int minpos = *available.begin();
				//cout << "pop " << Q.back() << " " << rates[minpos]*weights[Q.back()] << endl;
				available.erase(minpos);
				parkedcarpos[Q.back()] = minpos;
				parkedposcar[minpos] = Q.back();
				total+=rates[minpos]*weights[Q.back()];
				Q.pop_back();
			}
		}
	}
	cout << total << endl;
	
	
	
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:33:13: warning: unused variable 'i' [-Wunused-variable]
   33 |   for (auto i:Q) {
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 440 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 2 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 2 ms 500 KB Output is correct
19 Correct 4 ms 344 KB Output is correct
20 Correct 2 ms 344 KB Output is correct