답안 #481578

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
481578 2021-10-21T08:14:19 Z ssense Garage (IOI09_garage) C++14
100 / 100
2 ms 460 KB
#include <bits/stdc++.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long  ll;
using namespace std;
#define vint vector<int>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MOD2 998244353
#define MX 1000000000
#define MXL 1000000000000000000
#define PI (ld)2*acos(0.0)
#define nax 200005
#define pb push_back
#define sc second
#define fr first
#define int long long
#define endl '\n'
#define ld long double
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl
																																						int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}//ssense
void solve()
{
	int n, m;
	cin >> n >> m;
	vint r = read(n);
	vint w = read(m);
	set<int> available;
	for(int i = 0; i < n; i++)
	{
		available.insert(i);
	}
	deque<int> queue;
	map<int, int> mp;
	int ans = 0;
	for(int i = 0; i < 2*m; i++)
	{
		int now;
		cin >> now;
		if(now > 0)
		{
			if(available.size() == 0)
			{
				queue.pb(now);
			}
			else
			{
				int garage = *available.begin();
				ans+=w[now-1]*r[garage];
				mp[now] = garage;
				available.erase(available.begin());
			}
		}
		else
		{
			now = abs(now);
			available.insert(mp[now]);
			if(!queue.empty())
			{
				int rep = queue.front();
				int garage = *available.begin();
				ans+=w[rep-1]*r[garage];
				mp[rep] = garage;
				available.erase(available.begin());
				queue.pop_front();
			}
		}
	}
	cout << ans << endl;
}
 
int32_t main(){
	startt;
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
}
/*
 3 4
 2
 3
 5
 200
 100
 300
 800
 3
 2
 -3
 1
 4
 -4
 -2
 -1
 */
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 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 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct