답안 #289702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289702 2020-09-02T23:02:07 Z b00n0rp 쌀 창고 (IOI11_ricehub) C++17
100 / 100
21 ms 3328 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef pair<int,int> pii;
#define pb push_back
#define INF 1000000000
#define mp make_pair
#define MOD 1000000007
#define F first
#define S second
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPD(i,n) for(int i=(n);i>=0;i--)
#define FORD(i,a,b) for(int i=(a);i>=b;i--)
#define all(v) v.begin(),v.end()
#define itr ::iterator it;
#define WL(t) while(t --)

ll r,l,b;
ll a[1000005];
ll pref[1000005];
ll ans = 0;

ll cost(ll s, ll e){ // s -> start    e -> end     m -> mid
    ll m = (s+e)/2; 
    return (a[m]*(m-s))-(pref[m]-pref[s])+(pref[e+1]-pref[m+1])-(a[m]*(e-m));
}


ll besthub(int R, int L, int X[], ll B){
    r = R;
    l = L;
    b = B;

    pref[0] = 0;
    REP(i,r){
        a[i] = X[i];
        pref[i+1] = pref[i]+a[i];
    }
    ll low = 0,high = 0;
    while (high < r){
        ll cur = cost(low,high); 
       // cout << low << " " << high << " " << cur << endl;
        if (cur <= b){
            ans = max(ans,high-low+1);
            high ++;
        }
        else{
            low ++;
        }
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 0 ms 384 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 0 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 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 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 512 KB Output is correct
22 Correct 1 ms 512 KB Output is correct
23 Correct 1 ms 512 KB Output is correct
24 Correct 1 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 3 ms 512 KB Output is correct
27 Correct 1 ms 512 KB Output is correct
28 Correct 1 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 896 KB Output is correct
2 Correct 4 ms 896 KB Output is correct
3 Correct 21 ms 3320 KB Output is correct
4 Correct 19 ms 3328 KB Output is correct
5 Correct 8 ms 1664 KB Output is correct
6 Correct 8 ms 1664 KB Output is correct
7 Correct 16 ms 3080 KB Output is correct
8 Correct 16 ms 3072 KB Output is correct
9 Correct 8 ms 1536 KB Output is correct
10 Correct 8 ms 1664 KB Output is correct
11 Correct 20 ms 3328 KB Output is correct
12 Correct 20 ms 3328 KB Output is correct
13 Correct 9 ms 1664 KB Output is correct
14 Correct 13 ms 1664 KB Output is correct
15 Correct 15 ms 2560 KB Output is correct
16 Correct 15 ms 2560 KB Output is correct
17 Correct 18 ms 3072 KB Output is correct
18 Correct 20 ms 3072 KB Output is correct
19 Correct 19 ms 3200 KB Output is correct
20 Correct 19 ms 3200 KB Output is correct