Submission #924755

# Submission time Handle Problem Language Result Execution time Memory
924755 2024-02-09T15:59:50 Z parlimoos City (BOI06_city) C++14
20 / 100
479 ms 6228 KB
//Be Name KHODA
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using uint128 = unsigned __int128;

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<ll , x>
#define endl '\n'

ll n , t;
int k , m;
vector<uint128> a;
vector<int> lst;
uint128 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 ; i++) lst.pb((i + 1) * 4) , cnt += lst.back();
    m = (int)lst.size();
}
bool jg(ll e){
    ll cnt = 0;
    for(int i = 0 ; i < m ; i++){
        ll inx = int(ub(a.bg() , a.end() , e) - a.bg());
        cnt += inx * (1ll * i + 1ll * 1) * (1ll * 4);
        e -= t;
    }
    return (cnt > n);
}
ll bs(){
    ll l = -1 , r = t * a.back();
    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 sec = d;
    uint128 o = 0;
    for(uint128 i = 0 ; i < m ; i++){
        ll inx = int(lb(a.bg() , a.end() , sec) - a.bg());
        if(inx == 0) continue;
        // cout << (1ll * i + 1ll * 1) * (1ll * 4) * (ps[inx - 1] + (t * (1ll * i))) << "$\n";
        n -= inx * (1ll * i + 1ll * 1) * (1ll * 4);
        o += ((i + 1) * 4) * (ps[inx - 1] + (t * i));
        sec -= t;
    }
    if(n > 0){
        sec = d;
        for(uint128 i = 0 ; n > 0 and i < m ; i++ , sec -= t){
            ll inx = int(lb(a.bg() , a.end() , sec) - a.bg());
            if(inx >= k or a[inx] != sec) continue;
            uint128 dd = n;
            dd = min(dd , (i + 1) * 4);
            o += dd * (a[inx] + (t * i));
            n -= dd;
        }
    }
    stack<int> oo;
    while(o > 0){
        int d = o % 10;
        oo.push(d);
        o /= 10;
    }
    while(!oo.empty()){
        cout << oo.top();
        oo.pop();
    }
}

Compilation message

city.cpp: In function 'int main()':
city.cpp:70:27: warning: comparison of integer expressions of different signedness: 'uint128' {aka '__int128 unsigned'} and 'int' [-Wsign-compare]
   70 |     for(uint128 i = 0 ; i < m ; i++){
      |                         ~~^~~
city.cpp:80:41: warning: comparison of integer expressions of different signedness: 'uint128' {aka '__int128 unsigned'} and 'int' [-Wsign-compare]
   80 |         for(uint128 i = 0 ; n > 0 and i < m ; i++ , sec -= t){
      |                                       ~~^~~
city.cpp:82:35: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<__int128 unsigned>, __int128 unsigned>::value_type' {aka '__int128 unsigned'} and 'll' {aka 'long long int'} [-Wsign-compare]
   82 |             if(inx >= k or a[inx] != sec) continue;
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 53 ms 5076 KB Output isn't correct
3 Incorrect 2 ms 604 KB Output isn't correct
4 Incorrect 29 ms 860 KB Output isn't correct
5 Incorrect 4 ms 736 KB Output isn't correct
6 Correct 2 ms 604 KB Output is correct
7 Incorrect 479 ms 6228 KB Output isn't correct
8 Incorrect 54 ms 1240 KB Output isn't correct
9 Incorrect 41 ms 860 KB Output isn't correct
10 Incorrect 0 ms 348 KB Output isn't correct