Submission #197670

# Submission time Handle Problem Language Result Execution time Memory
197670 2020-01-22T07:32:47 Z Sakamotoo Garage (IOI09_garage) C++14
100 / 100
6 ms 376 KB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;

#define mp make_pair
#define fi first
#define se second

//mt19937 rng(time(NULL)); //int
mt19937_64 rng(time(NULL)); //Long Long
//shuffle(a.begin(),a.end(),rng); //shuffle
//rng(); //random

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	int n,m;
	cin>>n>>m;
	int c[n+1];
	for(int i=1; i<=n; i++){
		cin>>c[i];
	}
	int s[n+1];
	memset(s,0,sizeof s);
	int w[m+1];
	for(int i=1; i<=m; i++){
		cin>>w[i];
	}
	long long val=0;
	queue<int> q;
	for(int i=1; i<=2*m; i++){
		int x;
		cin>>x;
		if(x<0){
			x=-x;
			int j;
			for(j=1; j<=n; j++){
				if(s[j]==x) {
					s[j]=0;
					break;
				}
			}
			if(!q.empty()){
				s[j]=q.front();
				val+=c[j]*w[s[j]];
				q.pop();
			}
		}else {
		//	cout<<"tolol"<<endl;
			int j;
			for(j=1; j<=n; j++){
				if(s[j]==0){
					break;
				}
			}
			if(j==n+1) q.push(x);
			else {
				s[j]=x;
	//			cout<<j<<endl;
				val+=c[j]*w[x];
			}
		}
	//	cout<<val<<endl;
	}
	cout<<val<<endl;
}
# Verdict Execution time Memory 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 3 ms 248 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 6 ms 376 KB Output is correct
15 Correct 4 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 4 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 3 ms 348 KB Output is correct