Submission #969923

# Submission time Handle Problem Language Result Execution time Memory
969923 2024-04-25T21:00:47 Z urieg Rice Hub (IOI11_ricehub) C++17
0 / 100
4 ms 604 KB

#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;
/// for NC MoonDance

int besthub(int R, int L, int X[], long long B){

    vector<ll>x(R), p(R);
    for(int i=0;i<R;i++){
        x[i] = X[i];
        p[i] = x[i];
        if(i)p[i] += p[i-1];
    }
    ll INF = 7e18;
    ll ans = 1;
    for(int i=0;i<R;i++){
        ll l = 1, r = R;
        while(l<r){
            ll m = (l+r+1)/2;
            ll l_, r_;
            ll sum;
            if(m%2){
                l_ = i-m/2; r_ = i+m/2;
                if(0<=l_&&r_<R){
                    sum = p[r_] - p[i] - (x[i]*(r_-i));
                    sum += x[i]*(i-l_+1) - (!l_ ? 0 : p[i]-p[l_-1]);
                }
            }
            else{
                ll s1=INF,s2=INF;
                l_ = i-m/2+1; r_ = i+m/2;
                if(0<=l_&&r_<R){
                    s1 = p[r_] - p[i] - (x[i]*(r_-i));
                    s1 += x[i]*(i-l_+1) - (!l_ ? 0 : p[i]-p[l_-1]);
                }
                l_ = i-m/2; r_ = i+m/2-1;
                if(0<=l_&&r_<R){
                    s2 = p[r_] - p[i] - (x[i]*(r_-i));
                    s2 += x[i]*(i-l_+1) - (!l_ ? 0 : p[i]-p[l_-1]);
                }
                sum = min(s1,s2);
            }

            if(sum <= B)l = m;
            else r = m-1;
        }
        ans = max(ans, l);
    }
    return ans;
}




Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:47:13: warning: 'sum' may be used uninitialized in this function [-Wmaybe-uninitialized]
   47 |             if(sum <= B)l = m;
      |             ^~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 0 ms 376 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -