답안 #421842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
421842 2021-06-09T12:55:18 Z arayi 쌀 창고 (IOI11_ricehub) C++17
100 / 100
220 ms 2524 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#define lli long long
using namespace std;

const int N = 1e6 + 30;
int n;
lli pr[N];
lli s(int l, int r)
{
    lli ret = pr[r];
    if(l) ret -= pr[l-1];
    return ret;
}
int besthub(int N, int L, int X[], long long B)
{
    n = N;
    for (int i = 0; i < n; i++)
    {
        pr[i] = X[i];
        if(i) pr[i] += pr[i - 1];
    }
    int ret = 0;
    for (int i = 0; i < n; i++)
    {
        int l = 0, r = i, ans = 0;
        while(l <= r)
        {
            int mid = (l + r) / 2;
            lli sm = (lli)mid * 1LL * X[i] - s(i - mid, i - 1);
            int l1 = 0, r1 = n - i - 1, ans1 = 0;
            while(l1 <= r1)
            {
                int md = (l1 + r1) / 2;
                lli ss = -(lli)md * 1LL * X[i] + s(i + 1, i + md);
                if(sm + ss <= B) l1 = md + 1, ans1 = md;
                else r1 = md - 1;
            }
            if(sm <= B && (i + ans1 == n - 1 || X[i + ans1 + 1] - X[i] >= X[i] - X[i - mid])) l = mid + 1, ans = mid;
            else r = mid - 1;
            ret = max(ret, ans + ans1 + 1);
        }
        //cout << ans << " ";
        l = 0, r = n - i - 1, ans = 0;
        while(l <= r)
        {
            int mid = (l + r) / 2;
            lli sm = -(lli)mid * 1LL * X[i] + s(i + 1, i + mid);
            int l1 = 0, r1 = i, ans1 = 0;
            while(l1 <= r1)
            {
                int md = (l1 + r1) / 2;
                lli ss = (lli)md * 1LL * X[i] - s(i - md, i - 1);
                if(sm + ss <= B) l1 = md + 1, ans1 = md;
                else r1 = md - 1;
            }
            if(sm <= B && (i - ans1 == 0 || X[i] - X[i - ans1 - 1] >= X[i + mid] - X[i])) l = mid + 1, ans = mid;
            else r = mid - 1;
            ret = max(ret, ans + ans1 + 1);
        }
        //cout << ans << endl;
    }
    return ret;
}
# 결과 실행 시간 메모리 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 1 ms 204 KB Output is correct
5 Correct 1 ms 300 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 296 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 304 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 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 1 ms 204 KB Output is correct
17 Correct 0 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 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 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 1 ms 204 KB Output is correct
5 Correct 1 ms 304 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 2 ms 332 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 204 KB Output is correct
18 Correct 2 ms 204 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 6 ms 332 KB Output is correct
22 Correct 6 ms 332 KB Output is correct
23 Correct 4 ms 332 KB Output is correct
24 Correct 6 ms 392 KB Output is correct
25 Correct 5 ms 332 KB Output is correct
26 Correct 6 ms 332 KB Output is correct
27 Correct 7 ms 332 KB Output is correct
28 Correct 7 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 680 KB Output is correct
2 Correct 19 ms 668 KB Output is correct
3 Correct 139 ms 2520 KB Output is correct
4 Correct 197 ms 2520 KB Output is correct
5 Correct 61 ms 1196 KB Output is correct
6 Correct 59 ms 1228 KB Output is correct
7 Correct 127 ms 2232 KB Output is correct
8 Correct 181 ms 2228 KB Output is correct
9 Correct 92 ms 1220 KB Output is correct
10 Correct 92 ms 1204 KB Output is correct
11 Correct 129 ms 2524 KB Output is correct
12 Correct 220 ms 2508 KB Output is correct
13 Correct 70 ms 1260 KB Output is correct
14 Correct 72 ms 1260 KB Output is correct
15 Correct 93 ms 1868 KB Output is correct
16 Correct 134 ms 1868 KB Output is correct
17 Correct 111 ms 2284 KB Output is correct
18 Correct 172 ms 2276 KB Output is correct
19 Correct 118 ms 2388 KB Output is correct
20 Correct 183 ms 2508 KB Output is correct