Submission #211930

#TimeUsernameProblemLanguageResultExecution timeMemory
211930aloo123Garage (IOI09_garage)C++14
100 / 100
5 ms384 KiB
#pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ld long double #define f first #define s second #define mp make_pair #define pb push_back #define vll vector<ll> #define endl "\n" #define pll pair<ll,ll> #define all(x) (x).begin() , (x).end() #define in insert #define int ll using namespace std; using namespace __gnu_pbds; const ll N =(2e5); const ll MOD = 998244353; const ll INF = 1e16; const ll LOG = 25; long long binpow(long long a, long long b) { // a %= m; long long res = 1; while (b > 0) { if (b & 1) res = res * a ; a = a * a ; b >>= 1; } return res; } signed main() { ios_base::sync_with_stdio(0); cin.tie(NULL); ll n,m; cin >>n >> m; ll r[n+1]; for(int i =1;i<=n;i++) cin >> r[i]; ll w[m+1]; for(int i =1;i<=m;i++){ cin >> w[i]; } vector<bool> empty(n+1,true); vll pos(m+1); ll ans =0; queue<ll> q; for(int i = 1;i<=2*m;i++){ ll x; cin >>x; if(x > 0){ ll id=-1; for(int j = 1;j<=n;j++){ if(empty[j]){ id=j;break; } } if(id != -1){ empty[id]=false; pos[x] = id; ans+=(w[x]*r[id]); } else{ q.push(x); } } else{ ll p = pos[-x]; empty[p] = true; while(!q.empty()){ ll gg=q.front(); ll id=-1; for(int j = 1;j<=n;j++){ if(empty[j]){ id=j;break; } } if(id != -1){ empty[id]=false; pos[gg] = id; ans+=(w[gg]*r[id]); q.pop(); } else{ break; } } } } cout<<ans<<endl; }

Compilation message (stderr)

garage.cpp:2:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
garage.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
#Verdict Execution timeMemoryGrader output
Fetching results...