답안 #422241

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422241 2021-06-09T22:48:19 Z ScarletS 쌀 창고 (IOI11_ricehub) C++17
100 / 100
22 ms 1740 KB
#include <bits/stdc++.h>
using namespace std;

int besthub(int R, int L, int a[], long long B)
{
    int l=0,r=R,m,x,y;
    bool ok;
    //cout<<L<<"!!\n";
    long long cur;
    while (l<r)
    {
        ok=0;
        m=l+(r-l)/2+1;
        //cout<<m<<"!\n";
        cur=0;
        x=0;y=m-1;
        for (int i=0;i<=y/2;++i)
            cur-=a[i];
        for (int i=y/2+1;i<m;++i)
            cur+=a[i];
        //cout<<cur<<" ";
        // cout<<1LL*a[(x+y)/2]*((m-1)/2+1)<<" "<<-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<<"\n";
        //cout<<cur+1LL*a[(x+y)/2]*((m-1)/2+1)-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<<" ";
        if (cur+1LL*a[(x+y)/2]*((m-1)/2+1)-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<=B)
            ok=1;
        for (++x,++y;y<R;++x,++y)
        {
            //cout<<"\n"<<x<<" "<<y<<"\n";
            cur+=a[x-1];
            cur+=a[y];
            cur-=a[(x+y)/2]*2;
            // cout<<"+ "<<a[x-1]<<"\n";
            // cout<<"+ "<<a[y]<<"\n";
            // cout<<"- 2*"<<a[(x+y)/2]<<"\n";
            if (cur+1LL*a[(x+y)/2]*((m-1)/2+1)-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<=B)
                ok=1;
            //cout<<cur<<" ";
            //cout<<cur+1LL*a[(x+y)/2]*((m-1)/2+1)-1LL*a[(x+y)/2]*(m-(m-1)/2-1)<<" ";
        }
        //cout<<"\n";
        if (ok)
            l=m;
        else
            r=m-1;
    }
    return l;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 300 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 312 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 320 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 460 KB Output is correct
2 Correct 5 ms 440 KB Output is correct
3 Correct 22 ms 1692 KB Output is correct
4 Correct 16 ms 1740 KB Output is correct
5 Correct 8 ms 844 KB Output is correct
6 Correct 9 ms 844 KB Output is correct
7 Correct 18 ms 1380 KB Output is correct
8 Correct 15 ms 1356 KB Output is correct
9 Correct 8 ms 716 KB Output is correct
10 Correct 8 ms 696 KB Output is correct
11 Correct 16 ms 1672 KB Output is correct
12 Correct 16 ms 1732 KB Output is correct
13 Correct 9 ms 844 KB Output is correct
14 Correct 9 ms 844 KB Output is correct
15 Correct 12 ms 1340 KB Output is correct
16 Correct 12 ms 1356 KB Output is correct
17 Correct 16 ms 1612 KB Output is correct
18 Correct 14 ms 1580 KB Output is correct
19 Correct 15 ms 1612 KB Output is correct
20 Correct 15 ms 1612 KB Output is correct