답안 #289476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289476 2020-09-02T16:50:04 Z BeanZ 쌀 창고 (IOI11_ricehub) C++14
100 / 100
19 ms 768 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
int besthub(int r, int l, int x[], ll b){
        ll lf = 1, rt = 1;
        ll cur = 0, ans = 0;
        while (rt < r && (cur + (x[rt] - x[0])) <= b){
                cur = cur + (x[rt] - x[0]);
                rt++;
        }
        ans = max(ans, rt - lf + 1);
        for (int i = 2; i <= r; i++){
                cur = cur - (rt - i + 1) * (x[i - 1] - x[i - 2]);
                cur = cur + (i - lf) * (x[i - 1] - x[i - 2]);
                while (cur > b){
                        cur = cur - (x[i - 1] - x[lf - 1]);
                        lf++;
                }
                while (rt < r && (x[rt] - x[i - 1]) < (x[i - 1] - x[lf - 1])){
                        cur = cur + x[rt] - x[i - 1] - (x[i - 1] - x[lf - 1]);
                        rt++;
                        lf++;
                }
                while (lf > 1 && ((x[i - 1] - x[lf - 2]) < (x[rt - 1] - x[i - 1]))){
                        cur = cur + x[i - 1] - x[lf - 2] - (x[rt - 1] - x[i - 1]);
                        rt--;
                        lf--;
                }
                while (lf > 1 && rt < r){
                        ll costlf = x[i - 1] - x[lf - 2];
                        ll costrt = x[rt] - x[i - 1];
                        if ((min(costlf, costrt) + cur) > b) break;
                        if (costlf > costrt){
                                cur = cur + costrt;
                                rt++;
                        } else {
                                cur = cur + costlf;
                                lf--;
                        }
                }
                while (rt < r && (cur + x[rt] - x[i - 1]) <= b){
                        cur = cur + x[rt] - x[i - 1];
                        rt++;
                }
                while (lf > 1 && ((cur + x[i - 1] - x[lf - 2]) <= b)){
                        cur = cur + x[i - 1] - x[lf - 2];
                        lf--;
                }
                ans = max(ans, rt - lf + 1);
        }
        return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 0 ms 256 KB Output is correct
27 Correct 0 ms 256 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 18 ms 768 KB Output is correct
4 Correct 17 ms 768 KB Output is correct
5 Correct 8 ms 512 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 15 ms 760 KB Output is correct
8 Correct 15 ms 768 KB Output is correct
9 Correct 8 ms 512 KB Output is correct
10 Correct 8 ms 512 KB Output is correct
11 Correct 19 ms 768 KB Output is correct
12 Correct 19 ms 640 KB Output is correct
13 Correct 10 ms 512 KB Output is correct
14 Correct 9 ms 512 KB Output is correct
15 Correct 14 ms 640 KB Output is correct
16 Correct 14 ms 640 KB Output is correct
17 Correct 17 ms 692 KB Output is correct
18 Correct 17 ms 640 KB Output is correct
19 Correct 18 ms 640 KB Output is correct
20 Correct 18 ms 640 KB Output is correct