Submission #539467

# Submission time Handle Problem Language Result Execution time Memory
539467 2022-03-19T02:36:05 Z MurotY Garage (IOI09_garage) C++14
100 / 100
4 ms 468 KB
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define ll long long
using namespace std;
const int N=1e6+7, M=1e9+7;
ll a[N], b[N];
void solve()
{
	ll n, m;
	cin >> n >> m;
	
	for (int i=1;i<=n;i++) cin >> a[i];
	for (int i=1;i<=m;i++) cin >> b[i];
	
	map <ll,ll> mp, mp1;
	deque <ll> v;
	ll ans=0;
	for (int i=1;i<=2*m;i++){
		ll x;
		cin >> x;
		if (x > 0){
			bool ok=0;
			for (int i=1;i<=n;i++){
				if (mp[i] == 0) {
					mp[i]=1;
					ans+=a[i]*b[x];
					mp1[x]=i;
					ok=1;
					break;
				}
			}
			if (ok == 0) v.push_back(x);
		}
		else {
			if (v.size() == 0) mp[mp1[-x]]=0;
			else {
				bool ok=0;
			     ans+=a[mp1[-x]]*b[v[0]];
			     mp1[v[0]]=mp1[-x];
			     v.pop_front();
			}
		}
	}
	cout << ans;
}
int main()
{
	ios;
	int t=1;
//	cin >> t;
	while (t--){
		solve(); 
		cout << "\n";
	}
	return 0;
}

Compilation message

garage.cpp: In function 'void solve()':
garage.cpp:39:10: warning: unused variable 'ok' [-Wunused-variable]
   39 |     bool ok=0;
      |          ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 3 ms 468 KB Output is correct