답안 #698385

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
698385 2023-02-13T10:44:26 Z Boomyday 쌀 창고 (IOI11_ricehub) C++14
100 / 100
23 ms 3256 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!

using ii = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<db,db>;

using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vii = vector<ii>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define tcT template<class T
#define tcTU tcT, class U

tcT> using V = vector<T>;
tcT, size_t SZ> using AR = array<T,SZ>;
tcT> using PR = pair<T,T>;

// pairs
#define mp make_pair
#define f first
#define s second

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define len(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pb push_back
#define eb emplace_back
#define pf push_front

const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18; // not too close to LLONG_MAX
const ld PI = acos((ld)-1);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1}; // for every grid problem!!


vl fields;
vl field_prefs;



ll getScore(int l, int r){
    int m = (l+r)/2;
    ll sm = 0;
    sm +=  (m-l+1)*(fields[m-1]) - field_prefs[m]+field_prefs[l-1] ;
    sm += field_prefs[r]-field_prefs[m] - (r-m)*fields[m-1];
    return sm;
}



ll besthub(int R, int L, int X[], ll B){
    F0R(i, R) fields.pb(X[i]);
    field_prefs.resize(R+1);
    field_prefs[0] = 0;
    F0R(i, R) field_prefs[i+1] = fields[i] + field_prefs[i];
    int maxScore = 0;
    FOR(left, 1 ,R+1){
        int lower=left, upper=R;
        int mid = lower + (upper - lower) / 2;
        while(lower<=upper){

            ll sm = getScore(left, mid);
            if (sm<=B){
                maxScore = max(maxScore, mid-left+1);
                lower = mid+1;
                mid = lower + (upper - lower) / 2;
            }
            else {
                upper = mid-1;
                mid = lower + (upper - lower) / 2;
            };
        }

    }
    return maxScore;

}
/*
int main(){
    int R;
    ll L, B;
    cin >> R >> L >> B;
    int fd[R];
    F0R(i, R) cin >> fd[i];
    cout << besthub(R, L, fd, B) << endl;
}*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 724 KB Output is correct
2 Correct 3 ms 724 KB Output is correct
3 Correct 20 ms 2324 KB Output is correct
4 Correct 19 ms 2376 KB Output is correct
5 Correct 9 ms 1356 KB Output is correct
6 Correct 9 ms 1356 KB Output is correct
7 Correct 17 ms 2340 KB Output is correct
8 Correct 18 ms 2352 KB Output is correct
9 Correct 9 ms 1356 KB Output is correct
10 Correct 9 ms 1356 KB Output is correct
11 Correct 19 ms 2376 KB Output is correct
12 Correct 19 ms 2344 KB Output is correct
13 Correct 12 ms 1356 KB Output is correct
14 Correct 10 ms 1740 KB Output is correct
15 Correct 16 ms 2588 KB Output is correct
16 Correct 18 ms 2588 KB Output is correct
17 Correct 18 ms 3016 KB Output is correct
18 Correct 20 ms 3180 KB Output is correct
19 Correct 19 ms 3256 KB Output is correct
20 Correct 23 ms 3236 KB Output is correct