답안 #869022

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869022 2023-11-03T01:35:56 Z HuyQuang_re_Zero Garage (IOI09_garage) C++14
100 / 100
2 ms 4556 KB
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define N 200005
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
using namespace std;
ll n,m,c[N],w[N],i,u,res,ok[N],pos[N];
queue <int> car;
int Find()
{
    int i;
    for(i=1;i<=n;i++)
        if(ok[i]) break;
    return i;
}
int main()
{
  //  freopen("garage.inp","r",stdin);
    //freopen("garage.out","w",stdout);
    cin>>n>>m;
    for(i=1;i<=n;i++) cin>>c[i],ok[i]=1;
    for(i=1;i<=m;i++) cin>>w[i];
    for(i=1;i<=2*m;i++)
    {
        cin>>u;
        if(u>0) car.push(u); else ok[pos[-u]]=1;
        while(car.size()>0)
        {
            int u=car.front(),k=Find();
            if(k>n) break;
            pos[u]=k; ok[k]=0;
            res+=w[u]*c[k];
            car.pop();
        }
    }
    cout<<res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 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 4444 KB Output is correct
6 Correct 1 ms 4440 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 4444 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 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 2 ms 4556 KB Output is correct
18 Correct 2 ms 4444 KB Output is correct
19 Correct 2 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct