Submission #483436

# Submission time Handle Problem Language Result Execution time Memory
483436 2021-10-29T13:02:58 Z MohamedAliSaidane Rice Hub (IOI11_ricehub) C++14
100 / 100
14 ms 3276 KB
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> ti;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ld,ld> pld;
#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front
#define ff first
#define ss second
#define MOD (ll)(1000000007)
#define INF (ll) (1e18)
#define all(v) (v).begin(),(v).end()
const int nx[8] = {0, 0, 1, -1,1,1,-1,-1}, ny[8] = {1, -1, 0, 0,1,-1,1,-1}; //East, West, South, North+
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;}
ll lcm(ll a, ll b){return (a / gcd(a, b)) * b;}
////////////******SOLUTION******\\\\\\\\\\\

const int MAX_R = 1e5 + 4;
ll X[MAX_R] ;
ll b;
ll pref[MAX_R];
ll n;
bool test(ll x)
{
    for(ll i = 0; i<= n-x; i ++)
    {
        ll cent = i + x/2;
        ll pos = X[cent];
        ll tot = pos*(cent-i) - (pref[cent]-pref[i]);
        tot += pref[i+x]-pref[cent]-pos*(i+x-cent);
        if(tot <= b)
        {
            //cout << x << ' ' << i << ' ' << pos << ' ' << tot << '\n';
            return 1;
        }
    }
    return 0;
}
int besthub(int R, int L, int XX[], ll B)
{
    ll ans = 1;
    b = B;
    n = R;
    pref[0] = 0;
    for(int i = 0; i< R; i ++)
    {
        X[i] = XX[i];
        pref[i+1] = pref[i] + X[i];
    }
    int debut = 1;
    int fin = R;
    while(debut <= fin)
    {
        int mid = (debut+fin)/2;
        if(test(mid))
        {
            ans = mid;
            debut = mid + 1;
        }
        else
            fin = mid - 1;
    }
    //if(ans == 243)
        //cout << R << ' ' << L << ' ' << B << '\n';
    return ans;
}

// CHANGE YOUR APPROACH YEHDIK

Compilation message

ricehub.cpp:24:1: warning: multi-line comment [-Wcomment]
   24 | ////////////******SOLUTION******\\\\\\\\\\\
      | ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 324 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 0 ms 300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 444 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 820 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 11 ms 3264 KB Output is correct
4 Correct 14 ms 3204 KB Output is correct
5 Correct 6 ms 1612 KB Output is correct
6 Correct 6 ms 1612 KB Output is correct
7 Correct 9 ms 3020 KB Output is correct
8 Correct 10 ms 3020 KB Output is correct
9 Correct 5 ms 1484 KB Output is correct
10 Correct 6 ms 1484 KB Output is correct
11 Correct 11 ms 3276 KB Output is correct
12 Correct 11 ms 3256 KB Output is correct
13 Correct 6 ms 1612 KB Output is correct
14 Correct 6 ms 1612 KB Output is correct
15 Correct 8 ms 2508 KB Output is correct
16 Correct 12 ms 2552 KB Output is correct
17 Correct 12 ms 3020 KB Output is correct
18 Correct 10 ms 2892 KB Output is correct
19 Correct 11 ms 3068 KB Output is correct
20 Correct 10 ms 3128 KB Output is correct