# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
863749 | 2023-10-20T20:12:46 Z | AtabayRajabli | Garage (IOI09_garage) | C++17 | 4 ms | 4600 KB |
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // author : AtabeyR #define pb push_back #define pii pair<int, int> #define pll pair<ll, ll> #define all(v) v.begin(), v.end() #define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define sec second #define fi first #define int ll #define print(k) cerr << "Ans : "; cout << k << endl; #define ins insert #define bpc __builtin_popcountll #define skip continue #define endll '\n' #define gcd(a, b) __gcd(a, b) #define lcm(a, b) a*b / (__gcd(a, b)) typedef long long ll; typedef unsigned long long ull; const int oo = 0x3F3F3F3F; const int ooo = 0x3F3F3F3F3F3F3F3FLL; const int mod = 998244353; const int sz = 2e5; using namespace std; using namespace __gnu_pbds; template<class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>; void open(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } int n, m, k, r[sz], w[sz], a[sz], pos[sz]; int mex(set<int> s) { int cnt = 1; for(int i : s) { if(i == cnt)cnt++; else break; } return cnt; } void solve() { cin >> n >> m; for(int i = 1; i<=n; i++)cin >> r[i]; for(int i = 1; i<=m; i++)cin >> w[i]; for(int i = 1; i<=2*m; i++)cin >> a[i]; int ans = 0; queue<int> q; set<int> p; for(int i = 1; i<=m*2; i++) { if(a[i] > 0) { if(p.size() < n) { int mx = mex(p); ans += w[a[i]] * r[mx]; p.ins(mx); pos[a[i]] = mx; } else q.push(a[i]); } else { p.erase(pos[-a[i]]); if(p.size() < n && !q.empty()) { pos[q.front()] = pos[-a[i]]; ans += w[q.front()] * r[pos[q.front()]]; p.ins(pos[q.front()]); q.pop(); } } } cout << ans << endll; } int32_t main() { // open("i"); OPT int t = 1; //cin >> t; for(int i = 1; i<=t; i++) solve(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 4444 KB | Output is correct |
2 | Correct | 1 ms | 4568 KB | Output is correct |
3 | Correct | 1 ms | 4444 KB | Output is correct |
4 | Correct | 1 ms | 4444 KB | Output is correct |
5 | Correct | 1 ms | 4568 KB | Output is correct |
6 | Correct | 1 ms | 4444 KB | Output is correct |
7 | Correct | 1 ms | 4444 KB | Output is correct |
8 | Correct | 1 ms | 4444 KB | Output is correct |
9 | Correct | 1 ms | 4444 KB | Output is correct |
10 | Correct | 1 ms | 4440 KB | Output is correct |
11 | Correct | 1 ms | 4444 KB | Output is correct |
12 | Correct | 1 ms | 4444 KB | Output is correct |
13 | Correct | 1 ms | 4444 KB | Output is correct |
14 | Correct | 1 ms | 4444 KB | Output is correct |
15 | Correct | 2 ms | 4440 KB | Output is correct |
16 | Correct | 2 ms | 4444 KB | Output is correct |
17 | Correct | 3 ms | 4600 KB | Output is correct |
18 | Correct | 3 ms | 4444 KB | Output is correct |
19 | Correct | 1 ms | 4444 KB | Output is correct |
20 | Correct | 4 ms | 4444 KB | Output is correct |