답안 #856475

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
856475 2023-10-03T16:00:40 Z nnin 쌀 창고 (IOI11_ricehub) C++14
100 / 100
10 ms 3812 KB
#include "ricehub.h"
#include<bits/stdc++.h>
#define ll long long
#define pii pair<ll,int>
using namespace std;

int besthub(int n, int m, int x[], long long b) {
    int ans = 0;
    ll cost = 0;
    int l = 0;
    int r = 0;
    for(int i=0;i<n;i++) {
        if(i>0) cost += (ll)(x[i]-x[i-1])*(ll)(i-l-r+i-1);
        if(r<i) {
            cost += (ll)x[++r]-x[i];
        }
        while(cost>b) {
            if(x[r]-x[i] > x[i]-x[l]) {
                cost -= (ll)x[r--]-x[i];
            } else {
                cost -= (ll)x[i]-x[l++];
            }
        }
        while(true) {
            if(r<n-1 && x[r+1]-x[i] <= x[i]-x[l]) {
                cost += (ll)x[++r]-x[i];
                cost -= (ll)x[i]-x[l++];
            } else if(l>0 && x[i]-x[l-1] < x[r]-x[i]) {
                cost += (ll)x[i]-x[--l];
                cost -= (ll)x[r--]-x[i];
            } else if(r<n-1 && cost+(ll)x[r+1]-x[i] <= b) {
                cost += (ll)x[++r]-x[i];
            } else if(l>0 && cost+(ll)x[i]-x[l-1] <= b) {
                cost += (ll)x[i]-x[--l];
            } else {
                break;
            }
        }
        ans = max(ans, r-l+1);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 596 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 9 ms 2652 KB Output is correct
4 Correct 9 ms 2676 KB Output is correct
5 Correct 4 ms 2652 KB Output is correct
6 Correct 4 ms 2652 KB Output is correct
7 Correct 9 ms 2608 KB Output is correct
8 Correct 8 ms 2652 KB Output is correct
9 Correct 4 ms 2540 KB Output is correct
10 Correct 4 ms 2652 KB Output is correct
11 Correct 9 ms 2648 KB Output is correct
12 Correct 9 ms 2492 KB Output is correct
13 Correct 5 ms 2904 KB Output is correct
14 Correct 5 ms 2900 KB Output is correct
15 Correct 7 ms 3420 KB Output is correct
16 Correct 8 ms 3420 KB Output is correct
17 Correct 8 ms 3420 KB Output is correct
18 Correct 10 ms 3812 KB Output is correct
19 Correct 9 ms 3676 KB Output is correct
20 Correct 9 ms 3676 KB Output is correct