답안 #393149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393149 2021-04-22T20:08:46 Z MarcoMeijer 쌀 창고 (IOI11_ricehub) C++14
0 / 100
4 ms 868 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 && cost < B) {
            ub++;
            updateCost();
        }
        if(cost > B) {
            ub--;
            updateCost();
        }
        ans = max(ans, ub-lb+1);
        lb++;
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 868 KB Output isn't correct
2 Halted 0 ms 0 KB -