Submission #893832

# Submission time Handle Problem Language Result Execution time Memory
893832 2023-12-27T14:13:50 Z kigash Divide and conquer (IZhO14_divide) C++17
100 / 100
142 ms 11732 KB
#include "bits/stdc++.h"
using namespace std;       

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void IOIGold2024_InshAllah() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }

const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll mod = 1e9+7, N = 3e5+5;
ll x[N], g[N], d[N], mx[N];

void kigash() {
    // x[i]-x[j] <= d[i]-d[j-1] && g[i]-g[j-1] is max
    // x[i]-d[i] <= x[j]-d[j-1]
    ll n;
    cin>>n;
    for(ll i=1; i<=n; i++) {
        cin>>x[i]>>g[i]>>d[i];
        g[i] += g[i-1], d[i] += d[i-1];
    }
    ll l = 0, r = 1e15, ans = -1;
    while(l<=r) {
        ll mid = l+(r-l)/2, ok = 0;
        for(ll i=1; i<=n; i++) {
            mx[i] = max(mx[i-1], x[i]-d[i-1]);
            ll tl = 0, tr = i-1, pos = -1;
            while(tl<=tr) {
                ll tm = tl+(tr-tl)/2;
                if(g[i]-g[tm]>=mid) pos = tm, tl = tm+1;
                else tr = tm-1;
            }
            if(pos==-1) continue;
            if(x[i]-d[i]<=mx[pos+1]) {
                ok = 1;
                break;
            }
        }
        if(ok) ans = mid, l = mid+1;
        else r = mid-1;
    }
    cout<<ans<<"\n";
    return;
}

signed main(/*Kigash Amir*/) {
    // freopen("divide");
    IOIGold2024_InshAllah();
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) {
        kigash();
    }
}

Compilation message

divide.cpp: In function 'void freopen(std::string)':
divide.cpp:17:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:17:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Correct 1 ms 6612 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6648 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6636 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 3 ms 6492 KB Output is correct
23 Correct 6 ms 6748 KB Output is correct
24 Correct 6 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6744 KB Output is correct
13 Correct 1 ms 6612 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6648 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 2 ms 6636 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 3 ms 6492 KB Output is correct
23 Correct 6 ms 6748 KB Output is correct
24 Correct 6 ms 6748 KB Output is correct
25 Correct 4 ms 6492 KB Output is correct
26 Correct 9 ms 6748 KB Output is correct
27 Correct 9 ms 7000 KB Output is correct
28 Correct 47 ms 9820 KB Output is correct
29 Correct 49 ms 10076 KB Output is correct
30 Correct 103 ms 11732 KB Output is correct
31 Correct 119 ms 10332 KB Output is correct
32 Correct 98 ms 10588 KB Output is correct
33 Correct 100 ms 10320 KB Output is correct
34 Correct 126 ms 10464 KB Output is correct
35 Correct 140 ms 10980 KB Output is correct
36 Correct 142 ms 11148 KB Output is correct