# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
387604 | 2021-04-09T03:36:08 Z | bad_in_physics | Garage (IOI09_garage) | C++17 | 1 ms | 332 KB |
// i love pikachu #include<bits/stdc++.h> using namespace std; //data types #define ll long long int #define str string #define db long double //vector #define fi first #define se second #define pb push_back #define lb lower_bound #define up upper_bound //general #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() #define sz(x) (ll)(x).size() #define bg(x) (x).begin() #define ft front() #define dec() cout << fixed << setprecision(15) #define dbg(x) cerr << #x << " is " << x << '\n' #define ins insert #define yes cout << "YES\n" #define no cout << "NO\n" #define atyes cout << "Yes\n" #define atno cout << "No\n" //structs //permanent functions ll ceil(ll a, ll b) { if (a%b==0) { return a/b; } else { return a/b + 1; } } void setIO(str s = "") { ios_base::sync_with_stdio(false); cin.tie(0); if (sz(s)) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); } } //global permanent declarations vector<ll> dx = {0,1,0,-1,1,1,-1,-1}; vector<ll> dy = {1,0,-1,0,1,-1,1,-1}; //global temp declarations bool occupied[105]; //temporary functions int first_empty_place(int s) { for (int i=1; i<=s; i++) { if (occupied[i] == 0) { return i; } } return -1; } //solution void solve() { int n , m , ans = 0; cin >> n >> m; queue<int> q; vector<int> keeptrack(m+1,0); vector<int> c(n+1) , w(m+1); for (int i=1; i<=n; i++) { cin >> c[i]; } for (int i=1; i<=m; i++) { cin >> w[i]; } m *= 2; while (m--) { int a; cin >> a; if (a > 0) { int f = first_empty_place(n); if (f != -1) { keeptrack[a] = f; ans += w[a]*c[f]; occupied[f] = 1; } else { q.push(a); } } else { a = abs(a); occupied[keeptrack[a]] = 0; if (!q.empty()) { int f = first_empty_place(n); int t = q.front(); q.pop(); if (f != -1) { keeptrack[t] = f; ans += w[t]*c[f]; occupied[f] = 1; } } } } cout << ans; } int main(void) { setIO(); ll t = 1; //cin>>t; while (t--) { solve(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 204 KB | Output is correct |
2 | Correct | 1 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 204 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 1 ms | 320 KB | Output is correct |
8 | Correct | 1 ms | 308 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 | 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 | 328 KB | Output is correct |
16 | Correct | 1 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 | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |