답안 #581270

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581270 2022-06-22T12:42:09 Z stevancv 쌀 창고 (IOI11_ricehub) C++14
100 / 100
14 ms 2516 KB
#include <bits/stdc++.h>
#include "ricehub.h"
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int mxn = 1e5 + 2;
ll a[mxn];
ll n, k;
ll Get(ll l, ll r) {
    if (l > r) return 0LL;
    ll ans = a[r];
    if (l > 0) ans -= a[l - 1];
    return ans;
}
bool Can(ll x) {
    for (ll i = 0; i <= n - x; i++) {
        ll j = i + x - 1;
        ll o = i + j >> 1;
        ll val = Get(o, o);
        ll tr = val * (o - i + 1) - Get(i, o);
        tr += Get(o + 1, j) - val * (j - o);
        if (tr <= k) return true;
    }
    return false;
}
int besthub(int N, int M, int A[], ll K) {
    n = N; k = K;
    for (ll i = 0; i < n; i++) {
        a[i] = A[i];
        if (i > 0) a[i] += a[i - 1];
    }
    ll l = 1; ll r = n;
    int ans = l;
    while (l <= r) {
        ll mid = l + r >> 1;
        if (Can(mid)) {
            l = mid + 1;
            ans = mid;
        }
        else r = mid - 1;
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'bool Can(long long int)':
ricehub.cpp:22:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   22 |         ll o = i + j >> 1;
      |                ~~^~~
ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:39:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |         ll mid = l + r >> 1;
      |                  ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 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 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 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 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 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 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 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 340 KB Output is correct
22 Correct 1 ms 340 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 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 3 ms 468 KB Output is correct
3 Correct 11 ms 1364 KB Output is correct
4 Correct 11 ms 1364 KB Output is correct
5 Correct 6 ms 1212 KB Output is correct
6 Correct 6 ms 1212 KB Output is correct
7 Correct 12 ms 2216 KB Output is correct
8 Correct 11 ms 2148 KB Output is correct
9 Correct 8 ms 1108 KB Output is correct
10 Correct 6 ms 1088 KB Output is correct
11 Correct 13 ms 2516 KB Output is correct
12 Correct 14 ms 2448 KB Output is correct
13 Correct 7 ms 1272 KB Output is correct
14 Correct 7 ms 1236 KB Output is correct
15 Correct 9 ms 1856 KB Output is correct
16 Correct 9 ms 1932 KB Output is correct
17 Correct 12 ms 2260 KB Output is correct
18 Correct 11 ms 2256 KB Output is correct
19 Correct 12 ms 2320 KB Output is correct
20 Correct 11 ms 2364 KB Output is correct