답안 #211930

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
211930 2020-03-21T18:40:18 Z aloo123 Garage (IOI09_garage) C++14
100 / 100
5 ms 384 KB
#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

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")
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 256 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct