답안 #1003283

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003283 2024-06-20T08:33:56 Z vjudge1 쌀 창고 (IOI11_ricehub) C++17
100 / 100
10 ms 2652 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pf push_front
#define pb push_back
#define pi pair<int,int>
#define vi vector<int>

/*
int besthub(int n, int last, int x[], ll b){
    

    int ans = 0;
    int l , r;
    for(int i = 0; i < n; i++){
        
        l = i - (lower_bound(x.begin(), x.end(), max(0LL,x[i]-b))- x.begin());
        r =  upper_bound(x.begin(), x.end(), min((ll) last, x[i]+b)) - x.begin() - (i+1);
       // cout << x[i] << " " <<l << " " << r << endl;
        ans = max(l+r+1,ans);
    }
    
    return ans;

}

*/

int besthub(int n, int last, int x[], ll b){
    

    ll ans = 0;
    
    ll cnt;
    ll pref[n+1];
    pref[0] = 0;
    
    
 
    for(int i = 1; i <= n; i++){
        pref[i] = pref[i-1]+x[i-1];
    }
    
    if(b>=pref[n]){
        return n;
    }
    
  
    
    ll l = 1;
    ll final = 1;
    
    for(ll r =1; r <= n;r++){
        ll m = (l+r)/2;
       if(final==n) return n;
     //   ll val = pref[r] - pref[m] + (pref[m]-pref[max(0,l)]);
       ll val= ((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m))));
       //cout <<l << " "<< r << " " << val<<endl;
       
       
       // cout << val << endl;
        if( ((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m))))<= b){
           // cout << l << " " << r << endl;
            final = max(final,r-l+1);
        }
        else{
            while(((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m)))) > b && l<r){
                m = (l+r)/2;
                l++;
            }
            m = (l+r)/2;
            if(((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m))))<= b){
                 final = max(final,r-l+1);
            }
            
        }
    }
    
    return final;

}


Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:59:11: warning: unused variable 'val' [-Wunused-variable]
   59 |        ll val= ((x[m-1]*(m-l)) - (pref[m-1]-pref[l-1]) + ((pref[r]-pref[m]) - (x[m-1]*(r-m))));
      |           ^~~
ricehub.cpp:34:8: warning: unused variable 'ans' [-Wunused-variable]
   34 |     ll ans = 0;
      |        ^~~
ricehub.cpp:36:8: warning: unused variable 'cnt' [-Wunused-variable]
   36 |     ll cnt;
      |        ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 448 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 444 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 8 ms 2648 KB Output is correct
4 Correct 9 ms 2652 KB Output is correct
5 Correct 5 ms 1244 KB Output is correct
6 Correct 4 ms 1368 KB Output is correct
7 Correct 7 ms 2356 KB Output is correct
8 Correct 7 ms 2140 KB Output is correct
9 Correct 4 ms 1112 KB Output is correct
10 Correct 3 ms 1112 KB Output is correct
11 Correct 8 ms 2648 KB Output is correct
12 Correct 10 ms 2580 KB Output is correct
13 Correct 4 ms 1372 KB Output is correct
14 Correct 4 ms 1372 KB Output is correct
15 Correct 6 ms 1880 KB Output is correct
16 Correct 10 ms 2140 KB Output is correct
17 Correct 8 ms 2396 KB Output is correct
18 Correct 7 ms 2432 KB Output is correct
19 Correct 8 ms 2396 KB Output is correct
20 Correct 8 ms 2424 KB Output is correct