답안 #393150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393150 2021-04-22T20:10:10 Z MarcoMeijer 쌀 창고 (IOI11_ricehub) C++14
100 / 100
22 ms 2928 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int besthub(int R, int L, int X[], ll B) {
    int lb=0, ub=0;
    ll cost = 0;
    vll sm; sm.push_back(0);
    RE(i,R) sm.push_back(sm.back() + X[i]);
    auto updateCost = [&]() {
        int mid = (lb+ub)/2;
        cost = 0;
        // [lb,mid]
        cost += (mid-lb+1)*X[mid];
        cost -= sm[mid+1]-sm[lb];
        
        // [mid,ub]
        cost -= (ub-mid+1)*X[mid];
        cost += sm[ub+1]-sm[mid];
    };
    int ans = 0;
    while(lb < R) {
        while(ub < R-1 && cost <= B) {
            ub++;
            updateCost();
        }
        if(cost > B) {
            ub--;
            updateCost();
        }
        ans = max(ans, ub-lb+1);
        lb++;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 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 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 312 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 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 308 KB Output is correct
20 Correct 1 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 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 208 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 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 1 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 332 KB Output is correct
9 Correct 1 ms 208 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 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 308 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 208 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 216 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 460 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 420 KB Output is correct
26 Correct 2 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 720 KB Output is correct
2 Correct 4 ms 844 KB Output is correct
3 Correct 22 ms 2892 KB Output is correct
4 Correct 18 ms 2928 KB Output is correct
5 Correct 8 ms 1480 KB Output is correct
6 Correct 8 ms 1480 KB Output is correct
7 Correct 15 ms 2628 KB Output is correct
8 Correct 15 ms 2524 KB Output is correct
9 Correct 7 ms 1352 KB Output is correct
10 Correct 7 ms 1352 KB Output is correct
11 Correct 17 ms 2884 KB Output is correct
12 Correct 17 ms 2884 KB Output is correct
13 Correct 8 ms 1480 KB Output is correct
14 Correct 10 ms 1484 KB Output is correct
15 Correct 13 ms 2500 KB Output is correct
16 Correct 13 ms 2504 KB Output is correct
17 Correct 21 ms 2732 KB Output is correct
18 Correct 15 ms 2716 KB Output is correct
19 Correct 17 ms 2764 KB Output is correct
20 Correct 16 ms 2748 KB Output is correct