Submission #431239

# Submission time Handle Problem Language Result Execution time Memory
431239 2021-06-17T10:29:31 Z SAAD Garage (IOI09_garage) C++17
100 / 100
3 ms 384 KB
#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
//#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
int arr[(int)1e5], car[(int)1e5], pos[(int)1e5];
bool visa[1002];
int main() {
	int n, m;
  	ll ans = 0;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		visa[i] = true;
	}
	queue <int> q;
	int c = 0, p;
	for (int i = 1; i <= m; i++) {
		cin >> car[i];
	}
	for (int j = 0; j < m * 2; j++) {
		cin >> p;
		if (p < 0) {
			p = -p;
			visa[pos[p]] = true;
			if (q.size()) {
				pos[q.front()] = pos[p];
				visa[pos[p]] = false;
				ans += arr[pos[p]] * car[q.front()];
				q.pop();
			}
		}
		else {
			if (q.size()) q.push(p);
			else
				for (int i = 0; i < n; i++) {
					if (visa[i]) {
						visa[i] = false;
						pos[p] = i;
						ans += arr[i] * car[p];
						break;
					}
					if (i == n-1) q.push(p);
				}
		}
	}
	cout << ans;
	return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:38:6: warning: unused variable 'c' [-Wunused-variable]
   38 |  int c = 0, p;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 300 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 2 ms 204 KB Output is correct
17 Correct 2 ms 204 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 2 ms 332 KB Output is correct
20 Correct 3 ms 324 KB Output is correct