답안 #285218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
285218 2020-08-28T12:00:21 Z ec1117 쌀 창고 (IOI11_ricehub) C++17
42 / 100
21 ms 1536 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

int besthub(int r,int l, int x[],ll b) {
    int lhub=0;
    int p=0;
    int rhub=0;
    ll rice=0;//riceused
    ll y[r];
    for(int i=0;i<r;i++)y[i]=x[i];
    sort(y,y+r);
    int mx=1;
    while(rhub<r-1 && rice+y[rhub+1]-y[p]<=b){
        rhub++;
        rice+=y[rhub]-y[p];
    }
    mx=max(mx, rhub-lhub+1);
    while(p<r-1 && rhub<r){
        rice+=-(y[p+1]-y[p])*((rhub-p-1)-(p-lhub));
        p++;
        while(rice>b){//more hubs to the left than right
            rice-=y[p]-y[lhub];//remove lhub
            lhub++;
        }
        while(rhub<r-1 && p<r-1 && rice-(y[p]-y[lhub])+(y[rhub+1]-y[p])<=b){//do i add rhub+1?
            rice-=y[p]-y[lhub];
            lhub++;
            while(rhub<r-1 && rice+y[rhub+1]-y[p]<=b){
                rhub++;
                rice+=y[rhub]-y[p];
            }
            if(lhub>p)break;
        }
        while(lhub!=0 && rice+(y[p]-y[lhub-1])<=b){
            lhub--;
            rice+=y[p]-y[lhub];
        }
        mx=max(mx,rhub-lhub+1);
    }
    return mx;
}
//
//int main(){
//    int x[]={1,3,7};
//    cout << besthub(3,10,x,1)<<nl;
//    cout << besthub(3,10,x,2)<<nl;
//    cout << besthub(3,10,x,4)<<nl;
//    cout << besthub(3,10,x,6)<<nl;
//    return 0;
//}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Incorrect 0 ms 256 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 19 ms 1528 KB Output is correct
4 Correct 20 ms 1528 KB Output is correct
5 Correct 8 ms 896 KB Output is correct
6 Correct 8 ms 896 KB Output is correct
7 Correct 17 ms 1536 KB Output is correct
8 Correct 16 ms 1536 KB Output is correct
9 Correct 8 ms 896 KB Output is correct
10 Correct 8 ms 896 KB Output is correct
11 Correct 20 ms 1528 KB Output is correct
12 Correct 21 ms 1488 KB Output is correct
13 Incorrect 10 ms 1028 KB Output isn't correct
14 Halted 0 ms 0 KB -