Submission #120544

#TimeUsernameProblemLanguageResultExecution timeMemory
120544izanbfGarage (IOI09_garage)C++14
100 / 100
3 ms384 KiB
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define D(x) cerr << #x << " = " << (x) << ", " template <typename T> ostream& operator<<(ostream& _o_, const vector<T>& _v_){ \ if(!_v_.empty()){_o_<<'[';copy(_v_.begin(),_v_.end(),ostream_iterator<T>(_o_,", "));_o_<<"\b\b]";}return _o_;} #define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) typedef unsigned int uint; typedef unsigned long ul; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef unsigned char uchar; struct secure_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template<typename T> using V = vector<T>; template<typename T, typename U> using umap = unordered_map<T,U,secure_hash>; template<typename T> using uset = unordered_set<T,secure_hash>; template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template<typename T> using max_heap = priority_queue<T>; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m; cin >> n >> m; V<int> r(n); rep(i,0,n) cin >> r[i]; V<int> w(m); rep(i,0,m) cin >> w[i]; V<int> s(n, -1); int ans = 0; queue<int> q; rep(_,0,2*m) { int x; cin >> x; if (x < 0) { // Car gets out x = -x; rep(i,0,n) { if (s[i] == x) { s[i] = -1; break; } } } else { // Car gets in q.push(x); } if (not q.empty()) { int pos = -1; rep(i,0,n) { if (s[i] == -1) { pos = i; break; } } if (pos != -1) { ans += w[q.front()-1]*r[pos]; s[pos] = q.front(); q.pop(); } } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...