답안 #49758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49758 2018-06-02T18:48:23 Z gs13105 쌀 창고 (IOI11_ricehub) C++17
100 / 100
293 ms 3384 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>

using namespace std;

const int MAXR = 100000;

int pos[MAXR + 10];
int cnt[MAXR + 10];
int csum[MAXR + 10];
long long bsum[MAXR + 10];
int m = 1;

int besthub(int R, int L, int X[], long long B)
{
    for(int i = 0; i < R; i++)
    {
        if(i && X[i] != X[i - 1])
            m++;
        pos[m] = X[i];
        cnt[m]++;
    }

    for(int i = 1; i <= m; i++)
        csum[i] = csum[i - 1] + cnt[i];

    for(int i = 1; i <= m; i++)
        bsum[i] = bsum[i - 1] + 1LL * cnt[i] * pos[i];

    int res = 0;
    for(int i = 1; i <= m; i++)
    {
        int s = 0;
        int g = max(L - i, i - 1);
        while(s < g)
        {
            int x = (s + g + 1) / 2;
            int l = lower_bound(pos + 1, pos + m + 1, pos[i] - x) - pos;
            int r = upper_bound(pos + 1, pos + m + 1, pos[i] + x) - pos - 1;

            long long ls = (l == i) ? 0 : 1LL * pos[i] * (csum[i] - csum[l - 1]) - (bsum[i] - bsum[l - 1]);
            long long rs = (r == i) ? 0 : (bsum[r] - bsum[i - 1]) - 1LL * pos[i] * (csum[r] - csum[i - 1]);
            long long t = ls + rs;

            if(pos[i] - pos[l] == pos[r] - pos[i])
                t -= 1LL * (pos[i] - pos[l]) * (cnt[l] + cnt[r] - 1);
            else if(pos[i] - pos[l] > pos[r] - pos[i])
                t -= 1LL * (pos[i] - pos[l]) * (cnt[l] - 1);
            else
                t -= 1LL * (pos[r] - pos[i]) * (cnt[r] - 1);

            if(t <= B)
                s = x;
            else
                g = x - 1;
        }
        int l = lower_bound(pos + 1, pos + m + 1, pos[i] - s) - pos;
        int r = upper_bound(pos + 1, pos + m + 1, pos[i] + s) - pos - 1;

        long long ls = (l == i) ? 0 : 1LL * pos[i] * (csum[i] - csum[l - 1]) - (bsum[i] - bsum[l - 1]);
        long long rs = (r == i) ? 0 : (bsum[r] - bsum[i - 1]) - 1LL * pos[i] * (csum[r] - csum[i - 1]);
        long long t = ls + rs;
        int c = csum[r] - csum[l - 1];

        if(t > B)
        {
            int mx = max(pos[i] - pos[l], pos[r] - pos[i]);
            c -= (t - B + mx - 1) / mx;
        }

        res = max(res, c);
    }

    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 516 KB Output is correct
2 Correct 2 ms 628 KB Output is correct
3 Correct 3 ms 628 KB Output is correct
4 Correct 2 ms 628 KB Output is correct
5 Correct 2 ms 628 KB Output is correct
6 Correct 3 ms 628 KB Output is correct
7 Correct 2 ms 628 KB Output is correct
8 Correct 3 ms 628 KB Output is correct
9 Correct 3 ms 628 KB Output is correct
10 Correct 3 ms 628 KB Output is correct
11 Correct 3 ms 628 KB Output is correct
12 Correct 3 ms 628 KB Output is correct
13 Correct 2 ms 628 KB Output is correct
14 Correct 2 ms 628 KB Output is correct
15 Correct 3 ms 628 KB Output is correct
16 Correct 3 ms 628 KB Output is correct
17 Correct 2 ms 732 KB Output is correct
18 Correct 3 ms 732 KB Output is correct
19 Correct 2 ms 732 KB Output is correct
20 Correct 2 ms 732 KB Output is correct
21 Correct 2 ms 740 KB Output is correct
22 Correct 2 ms 740 KB Output is correct
23 Correct 2 ms 740 KB Output is correct
24 Correct 2 ms 740 KB Output is correct
25 Correct 3 ms 740 KB Output is correct
26 Correct 2 ms 740 KB Output is correct
27 Correct 3 ms 740 KB Output is correct
28 Correct 3 ms 740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 796 KB Output is correct
2 Correct 2 ms 796 KB Output is correct
3 Correct 3 ms 796 KB Output is correct
4 Correct 4 ms 796 KB Output is correct
5 Correct 2 ms 796 KB Output is correct
6 Correct 2 ms 796 KB Output is correct
7 Correct 2 ms 796 KB Output is correct
8 Correct 2 ms 796 KB Output is correct
9 Correct 3 ms 796 KB Output is correct
10 Correct 3 ms 796 KB Output is correct
11 Correct 3 ms 796 KB Output is correct
12 Correct 3 ms 796 KB Output is correct
13 Correct 3 ms 796 KB Output is correct
14 Correct 3 ms 796 KB Output is correct
15 Correct 2 ms 796 KB Output is correct
16 Correct 3 ms 796 KB Output is correct
17 Correct 3 ms 796 KB Output is correct
18 Correct 4 ms 796 KB Output is correct
19 Correct 5 ms 796 KB Output is correct
20 Correct 4 ms 796 KB Output is correct
21 Correct 4 ms 796 KB Output is correct
22 Correct 3 ms 796 KB Output is correct
23 Correct 7 ms 956 KB Output is correct
24 Correct 7 ms 976 KB Output is correct
25 Correct 10 ms 1008 KB Output is correct
26 Correct 12 ms 1048 KB Output is correct
27 Correct 13 ms 1048 KB Output is correct
28 Correct 12 ms 1136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 1524 KB Output is correct
2 Correct 54 ms 1524 KB Output is correct
3 Correct 219 ms 3384 KB Output is correct
4 Correct 293 ms 3384 KB Output is correct
5 Correct 9 ms 3384 KB Output is correct
6 Correct 10 ms 3384 KB Output is correct
7 Correct 18 ms 3384 KB Output is correct
8 Correct 21 ms 3384 KB Output is correct
9 Correct 23 ms 3384 KB Output is correct
10 Correct 23 ms 3384 KB Output is correct
11 Correct 185 ms 3384 KB Output is correct
12 Correct 246 ms 3384 KB Output is correct
13 Correct 128 ms 3384 KB Output is correct
14 Correct 128 ms 3384 KB Output is correct
15 Correct 137 ms 3384 KB Output is correct
16 Correct 194 ms 3384 KB Output is correct
17 Correct 179 ms 3384 KB Output is correct
18 Correct 223 ms 3384 KB Output is correct
19 Correct 206 ms 3384 KB Output is correct
20 Correct 257 ms 3384 KB Output is correct