답안 #924741

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
924741 2024-02-09T15:40:27 Z parlimoos City (BOI06_city) C++14
40 / 100
408 ms 5452 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;
int k , m;
vector<ll> a;
vector<int> lst;
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 ; 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 o = 0 , sec = d;
    for(int 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 += (1ll * i + 1ll * 1) * (1ll * 4) * (ps[inx - 1] + (t * (1ll * i)));
        sec -= t;
    }
    if(n > 0){
        sec = d;
        for(int 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;
            o += min(n , (1ll * i + 1ll * 1) * (1ll * 4)) * (a[inx] + (t * (1ll * i)));
            n -= min(n , (1ll * i + 1ll * 1) * (1ll * 4));
        }
    }
    cout << o;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 54 ms 5416 KB Output is correct
3 Correct 2 ms 600 KB Output is correct
4 Incorrect 24 ms 604 KB Output isn't correct
5 Incorrect 3 ms 736 KB Output isn't correct
6 Correct 2 ms 604 KB Output is correct
7 Incorrect 408 ms 5452 KB Output isn't correct
8 Incorrect 47 ms 1020 KB Output isn't correct
9 Incorrect 37 ms 856 KB Output isn't correct
10 Incorrect 0 ms 344 KB Output isn't correct