답안 #798133

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
798133 2023-07-30T11:41:36 Z AkramElOmrani Garage (IOI09_garage) C++17
100 / 100
1 ms 340 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#define ios ios_base::sync_with_stdio(0);cin.tie(0);

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int gen(int a, int b) {return (ll)rng() % (b - a + 1) + a;}


signed main()
{
	ios
	int n, m; cin >> n >> m;
	vector<int> r(n); for(int& x : r) cin >> x;
	vector<int> w(m); for(int& x : w) cin >> x;
	vector<int> parked(m, -1);
	queue<int> q;
	set<int> s;
	vector<bool> left(m);
	for(int i = 0; i < n; ++i) s.insert(i);


	int ans = 0;
	for(int i = 0; i < 2 * m; ++i) {
		int car; cin >> car;
		// dbg(i)
		if(car > 0) {
			car--;
			q.push(car);
		} else {
			car *= -1;
			car--;
			left[car] = 1;
			if(parked[car] != -1) {
				s.insert(parked[car]);
			}
		}
		while(!q.empty() && left[q.front()]) q.pop();
		if(!s.empty() && !q.empty()) {
			auto pp = q.front(); q.pop();
			auto ss = *s.begin(); s.erase(s.begin());
			// dbg(pp, w[pp], r[ss])
			ans += w[pp] * r[ss];
			parked[pp] = ss;
		}
	}
	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct