답안 #522607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
522607 2022-02-05T09:20:08 Z ddy888 쌀 창고 (IOI11_ricehub) C++17
100 / 100
47 ms 9576 KB
#undef _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define fi first
#define si second
#define ar array
#define ll long long 
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;  
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

#include "ricehub.h"

ll N, M, K, ans;
ll pre[100010];
vector<ll> A;
map<ll, ll> cnt;

ll sum(int lx, int rx) {
    return pre[rx] - pre[lx - 1];
}

bool check(int lx, int rx) {
    ll x = A[(rx + lx + 1) / 2];
    auto it1 = lower_bound(A.begin() + lx, A.begin() + rx + 1, x);
    auto it2 = upper_bound(A.begin() + lx, A.begin() + rx + 1, x);
    ll small = 0, big = 0;
    if (it1 != A.begin()) --it1, small = (it1 - A.begin()) - lx + 1;
    if (it2 != A.end()) big = rx - (it2 - A.begin()) + 1;
    ll cost = x * (ll)(small - big) - (ll)(sum(lx, (it1 - A.begin())) - sum((it2 - A.begin()), rx));
    return cost <= K;
}

int besthub(int R, int L, int X[], long long B)
{
    N = R; M = L; K = B;
    A.resize(N + 1);
    for (int i = 1; i <= N; ++i) {
        A[i] = X[i - 1];
        ++cnt[A[i]];
        pre[i] = pre[i - 1] + A[i];
    }
    int rx = 1;
    for (int i = 1; i <= N; ++i) {
        while (rx <= N && check(i, rx)) {
            ans = max(ans, (ll)rx - i + 1);
            ++rx;
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 2 ms 588 KB Output is correct
24 Correct 2 ms 588 KB Output is correct
25 Correct 2 ms 716 KB Output is correct
26 Correct 2 ms 716 KB Output is correct
27 Correct 2 ms 716 KB Output is correct
28 Correct 2 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1868 KB Output is correct
2 Correct 6 ms 1868 KB Output is correct
3 Correct 41 ms 8468 KB Output is correct
4 Correct 34 ms 9576 KB Output is correct
5 Correct 11 ms 1584 KB Output is correct
6 Correct 8 ms 1604 KB Output is correct
7 Correct 22 ms 3340 KB Output is correct
8 Correct 22 ms 3284 KB Output is correct
9 Correct 13 ms 2168 KB Output is correct
10 Correct 16 ms 2096 KB Output is correct
11 Correct 47 ms 9572 KB Output is correct
12 Correct 34 ms 9488 KB Output is correct
13 Correct 18 ms 4688 KB Output is correct
14 Correct 15 ms 4640 KB Output is correct
15 Correct 24 ms 7108 KB Output is correct
16 Correct 25 ms 7176 KB Output is correct
17 Correct 31 ms 8476 KB Output is correct
18 Correct 38 ms 8520 KB Output is correct
19 Correct 35 ms 8992 KB Output is correct
20 Correct 35 ms 8992 KB Output is correct