Submission #924775

# Submission time Handle Problem Language Result Execution time Memory
924775 2024-02-09T16:18:08 Z parlimoos City (BOI06_city) C++14
90 / 100
295 ms 736 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back
#define pp pop_back
#define lb lower_bound
#define ub upper_bound
#define cl clear
#define bg begin
#define arr(x) array<int , x>
#define endl '\n'

ll n , t , m , k;
vector<ll> a;
ll ps[20000];

void init(){
    for(int i = 0 ; i < k ; i++){
        ps[i] = a[i];
        if(i > 0) ps[i] += ps[i - 1];
    }
    ll cnt = 0;
    for(int i = 0 ; cnt < n ; m++ , i++) cnt += 1ll * ((i + 1) * 4);
}
bool jg(ll e){
    ll cnt = 0;
    for(ll i = 0 ; i < m ; i++){
        ll inx = int(ub(a.bg() , a.end() , e) - a.bg());
        cnt += inx * (4 * (i + 1));
        e -= t;
    }
    return (cnt > n);
}
ll bs(){
    ll l = -1 , r = t * a.back() + 1;
    while(r - l - 1 > 1){
        ll c = l + (r - l - 1) / 2 + 1;
        if(jg(c)) r = c;
        else l = c - 1;
    }
    if(r - l - 1 == 1){
        if(jg(r - 1)) return r - 1;
    }
    return r;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> t >> k;
    for(int i = 0 ; i < k ; i++){
        ll d;
        cin >> d;
        a.pb(d);
    }
    init();
    ll d = bs();

    ll o = 0 , sec = d - 1;
    for(ll i = 0 ; i < m ; i++){
        ll inx = int(ub(a.bg() , a.end() , sec) - a.bg());
        if(inx == 0) continue;
        n -= inx * ((i + 1) * 4);
        o += ((i + 1) * 4) * (ps[inx - 1]);
        o += inx * ((i + 1) * 4) * (t * i);
        sec -= t;
    }
    if(n > 0){
        sec = d;
        for(ll i = 0 ; n > 0 and i < m ; i++ , sec -= t){
            ll inx = int(binary_search(a.bg() , a.end() , sec));
            if(inx >= k) continue;
            o += min(n , ((i + 1) * 4)) * d;
            n -= min(n , ((i + 1) * 4));
        }
    }
    cout << o;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 45 ms 428 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Correct 18 ms 348 KB Output is correct
5 Incorrect 3 ms 460 KB Output isn't correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 295 ms 736 KB Output is correct
8 Correct 36 ms 348 KB Output is correct
9 Correct 30 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct