답안 #742928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
742928 2023-05-17T06:12:28 Z vjudge1 쌀 창고 (IOI11_ricehub) C++17
100 / 100
15 ms 2552 KB
#include <bits/stdc++.h>
#include "ricehub.h"
#define DEBUG 0
using namespace std;
 
const int N = 1e5 + 10;
 
int n;
long long lim;
long long x[N];
 
bool check(int sz) {
    int l = 1, r = sz;
    int mid = (l + r) / 2;
 
    int sz_l = mid - l, sz_r = r - mid;
    long long L = 0, R = 0;
    for(int i = l; i < mid; i++) {
        L += x[mid] - x[i];
    }
    for(int i = mid + 1; i <= r; i++) {
        R += x[i] - x[mid];
    }
 
    if(L + R <= lim) {
        return true;
    }
    while(r < n) {
        L -= x[mid] - x[l];
        R -= (x[mid + 1] - x[mid]) * sz_r;
        l++, r++, mid++;
        L += (x[mid] - x[mid - 1]) * sz_l;
        R += x[r] - x[mid];
        if(L + R <= lim) {
            return true;
        }
    }
    return false;
}
 
int besthub(int R, int L, int X[], long long B) {
    n = R;
    lim = B;
    for(int i = 1; i <= R; i++) {
        x[i] = X[i - 1];
    }
 
    int l = 1, r = R, pos = -1;
    while(l <= r) {
        int mid = (l + r) / 2;
 
        if(check(mid) == true) {
            pos = mid;
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }
    }
    return pos;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 228 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 312 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 224 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 0 ms 308 KB Output is correct
22 Correct 1 ms 308 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 312 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 320 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 320 KB Output is correct
26 Correct 1 ms 356 KB Output is correct
27 Correct 1 ms 312 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 688 KB Output is correct
3 Correct 11 ms 2468 KB Output is correct
4 Correct 11 ms 2516 KB Output is correct
5 Correct 7 ms 1244 KB Output is correct
6 Correct 7 ms 1236 KB Output is correct
7 Correct 10 ms 2132 KB Output is correct
8 Correct 10 ms 2144 KB Output is correct
9 Correct 5 ms 1108 KB Output is correct
10 Correct 5 ms 1108 KB Output is correct
11 Correct 13 ms 2552 KB Output is correct
12 Correct 15 ms 2456 KB Output is correct
13 Correct 6 ms 1236 KB Output is correct
14 Correct 6 ms 1236 KB Output is correct
15 Correct 8 ms 1872 KB Output is correct
16 Correct 10 ms 1876 KB Output is correct
17 Correct 10 ms 2260 KB Output is correct
18 Correct 11 ms 2188 KB Output is correct
19 Correct 11 ms 2388 KB Output is correct
20 Correct 11 ms 2296 KB Output is correct