답안 #57524

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57524 2018-07-15T08:12:47 Z Bodo171 Garage (IOI09_garage) C++14
100 / 100
6 ms 788 KB
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=2005;
int r[nmax],w[nmax],loc[nmax],lib[nmax],q[nmax];
int n,m,i,j,ind,p,u,x;
long long ans;
int main()
{
    //freopen("data.in","r",stdin);
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>r[i];
        lib[i]=1;
    }
    for(i=1;i<=m;i++)
    {
        cin>>w[i];
    }
    p=1;
    for(i=1;i<=2*m;i++)
    {
        cin>>x;
        if(x>0)
        {
            ind=1;
            while(ind<=n&&(!lib[ind])) ind++;
            if(ind==n+1) q[++u]=x;
            else lib[ind]=0,ans+=1LL*r[ind]*w[x],loc[x]=ind;
        }
        else
        {
            x*=(-1);
            lib[loc[x]]=1;
            if(p<=u)
            {
                loc[q[p]]=loc[x];
                lib[loc[x]]=0;
                ans+=1LL*r[loc[x]]*w[q[p]];
                p++;
            }
        }
    }
    cout<<ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 496 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 2 ms 524 KB Output is correct
6 Correct 2 ms 536 KB Output is correct
7 Correct 3 ms 540 KB Output is correct
8 Correct 2 ms 548 KB Output is correct
9 Correct 2 ms 548 KB Output is correct
10 Correct 2 ms 556 KB Output is correct
11 Correct 2 ms 608 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 4 ms 640 KB Output is correct
14 Correct 4 ms 648 KB Output is correct
15 Correct 4 ms 660 KB Output is correct
16 Correct 5 ms 676 KB Output is correct
17 Correct 6 ms 696 KB Output is correct
18 Correct 5 ms 720 KB Output is correct
19 Correct 4 ms 748 KB Output is correct
20 Correct 4 ms 788 KB Output is correct