답안 #553570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
553570 2022-04-26T09:28:11 Z andrei_boaca Snowball (JOI21_ho_t2) C++14
33 / 100
1639 ms 13744 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll INF=1e9;
ll n,q,x[200005],w[200005],smax[200005],smin[200005],sol[200005];
ll getfst(ll need)
{
    if(need>=0)
    {
        ll st=1;
        ll dr=q;
        ll poz=INF;
        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            if(smax[mij]>=need)
            {
                poz=mij;
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        return poz;
    }
    else
    {
        ll st=1;
        ll dr=q;
        ll poz=INF;
        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            if(smin[mij]<=need)
            {
                poz=mij;
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        return poz;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)
        cin>>x[i];
    for(int i=1;i<=q;i++)
        cin>>w[i];
    smax[1]=w[1];
    smin[1]=w[1];
    for(int i=2;i<=q;i++)
    {
        w[i]=w[i-1]+w[i];
        smax[i]=max(smax[i-1],w[i]);
        smin[i]=min(smin[i-1],w[i]);
    }
    for(int i=1;i<n;i++)
    {
        ll p1=x[i];
        ll p2=x[i+1];
        ll st=p1+1;
        ll dr=p2;
        ll nr=0;
        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            ll needL=mij-p1;
            ll needR=(mij-1)-p2;
            ll fstL=getfst(needL);
            ll fstR=getfst(needR);
            if(fstL<fstR&&fstL!=INF)
            {
                nr=mij-p1;
                st=mij+1;
            }
            else
                dr=mij-1;
        }
        sol[i]+=nr;
        st=p1;
        dr=p2-1;
        nr=0;
        while(st<=dr)
        {
            ll mij=(st+dr)/2;
            ll needL=mij+1-p1;
            ll needR=mij-p2;
            ll fstL=getfst(needL);
            ll fstR=getfst(needR);
            if(fstR<fstL&&fstR!=INF)
            {
                nr=p2-mij;
                dr=mij-1;
            }
            else
                st=mij+1;
        }
        sol[i+1]+=nr;
    }
    sol[1]+=abs(smin[q]);
    sol[n]+=smax[q];
    for(int i=1;i<=n;i++)
        cout<<sol[i]<<'\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 11 ms 468 KB Output is correct
5 Correct 9 ms 468 KB Output is correct
6 Correct 8 ms 456 KB Output is correct
7 Correct 7 ms 468 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 5 ms 460 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 13 ms 468 KB Output is correct
16 Correct 9 ms 468 KB Output is correct
17 Correct 7 ms 464 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 11 ms 468 KB Output is correct
5 Correct 9 ms 468 KB Output is correct
6 Correct 8 ms 456 KB Output is correct
7 Correct 7 ms 468 KB Output is correct
8 Correct 6 ms 468 KB Output is correct
9 Correct 5 ms 460 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 13 ms 468 KB Output is correct
16 Correct 9 ms 468 KB Output is correct
17 Correct 7 ms 464 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 468 KB Output is correct
20 Correct 26 ms 7104 KB Output is correct
21 Correct 28 ms 6904 KB Output is correct
22 Correct 29 ms 6716 KB Output is correct
23 Correct 41 ms 6604 KB Output is correct
24 Correct 221 ms 7000 KB Output is correct
25 Correct 1621 ms 13388 KB Output is correct
26 Correct 1639 ms 13372 KB Output is correct
27 Correct 1543 ms 13004 KB Output is correct
28 Correct 1506 ms 13360 KB Output is correct
29 Correct 1401 ms 12704 KB Output is correct
30 Correct 815 ms 12092 KB Output is correct
31 Correct 135 ms 11416 KB Output is correct
32 Correct 95 ms 11644 KB Output is correct
33 Correct 120 ms 1804 KB Output is correct
34 Correct 1505 ms 13744 KB Output is correct
35 Correct 1470 ms 13152 KB Output is correct
36 Correct 1622 ms 13356 KB Output is correct
37 Correct 1476 ms 13240 KB Output is correct
38 Correct 1553 ms 13212 KB Output is correct
39 Correct 1564 ms 13260 KB Output is correct
40 Correct 868 ms 13128 KB Output is correct
41 Incorrect 28 ms 7756 KB Output isn't correct
42 Halted 0 ms 0 KB -