Submission #1147942

#TimeUsernameProblemLanguageResultExecution timeMemory
1147942andrewp나일강 (IOI24_nile)C++20
36 / 100
26 ms6336 KiB
//Dedicated to my love, ivaziva
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
const int N=1e5+5;

int n, q;
int w[N], a[N], b[N], e[N];

vector<ll> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
    n=sz(W), q=sz(E);
    for (int i=1; i<=n; i++) 
        w[i]=W[i-1], a[i]=A[i-1], b[i]=B[i-1];
    for (int i=1; i<=q; i++) 
        e[i]=E[i-1];
    if (q<=5&&n<=2000&&W==vector<int>(n, 1)) { 
        if (n%2==0) { 
            ll ans=0;   
            for (int i=1; i<=n; i++) 
                ans+=b[i];
            return (vector<ll>(q, ans)); 
        }   
        else {
            ll sumb=0, ans=(ll)(1e18);
            for (int i=1; i<=n; i++) 
                sumb+=b[i];
            for (int i=1; i<=n; i++) 
                ans=min(ans, a[i]+sumb-b[i]); 
            return (vector<ll>(q, ans)); 
        }
    } 
    vector<int> sub2;
    for (int i=0; i<n; i++) sub2.pb(i+1);
    if (q<=5&&W==sub2) {
        if (n%2==0) {  
            ll ans=0;   
            for (int i=1; i<=n; i++) 
                ans+=b[i];
            return (vector<ll>(q, ans));
        }   
        else { 
            vector<ll> ret;         
            for (int i=1; i<=q; i++) {
                if (e[i]>=2) {
                    ll sumb=0, ans=(ll)(1e18);
                    for (int i=1; i<=n; i++) 
                        sumb+=b[i];
                    for (int i=1; i<=n; i++) 
                        ans=min(ans, a[i]+sumb-b[i]);   
                    ret.pb(ans); 
                }
                else {
                    ll sumb=0, ans=(ll)(1e18);
                    for (int i=1; i<=n; i++) 
                        sumb+=b[i];
                    for (int i=1; i<=n; i++) 
                        if (i%2==1)
                            ans=min(ans, a[i]+sumb-b[i]);   
                    ret.pb(ans); 
                }
            }
            return ret; 
        }
    }
    if (q<=5&&A==vector<int>(n, 2)&&B==vector<int>(n, 1)) {
        sort(w+1, w+n+1);
        vector<ll> ret;
        for (int j=1; j<=q; j++) {
            ll ans=n, curr=1; 
            for (int i=1; i<n; i++) {
                if (w[i+1]-w[i]>e[j]) {
                    ans+=curr%2; 
                    curr=1;
                    continue;
                }
                curr++;
            }
            ans+=curr%2; 
            ret.pb(ans);
        }
        return ret;     
    }
    if (q<=5&&n<=2000) {  
        vector<pair<ll, ll>> vec;
        for (int i=1; i<=n; i++) { 
            vec.pb(make_pair(w[i], a[i]-b[i])); 
        }  
        sort(all(vec));
        ll sumb=0;
        for (int i=1; i<=n; i++) {
            sumb+=b[i];
        }
        vector<ll> ret;
        for (int j=1; j<=q; j++) { 
            ll ans=sumb, curr_sz=1, curr_mn=vec[0].second;    
            for (int i=0; i<n-1; i++) {
                if (vec[i+1].first-vec[i].first>e[j]) {
                    if (curr_sz%2==1) 
                        ans+=curr_mn; 
                    curr_mn=vec[i+1].second;
                    curr_sz=1;
                    continue;
                }
                curr_mn=min(curr_mn, vec[i+1].second);
                curr_sz++; 
            }
            if (curr_sz%2==1) 
                ans+=curr_mn;  
            ret.pb(ans);
        }
        return ret; 
    } 
    return vector<ll>(q, -1); 
}

// int32_t main () {
//     ios::sync_with_stdio(false), cin.tie(0);

//     int N_;
//     cin >> N_;
//     vector<int> W(N_), A(N_), B(N_);
//     for (int i=0; i<N_; i++) 
//         cin >> W[i] >> A[i] >> B[i];
//     int Q_;
//     cin >> Q_;
//     vector<int> E(Q_);
//     for (int i=0; i<Q_; i++) 
//         cin >> E[i];
//     vector<ll> ans=calculate_costs(W, A, B, E);
//     cout << "-------------------\n";
//     cout << "Answer:\n"; 
//     for (ll x:ans) {
//         cout << x << ' ';
//     }
//     cout << '\n';
//     return 0;
// }
/*
5 
15 5 1
12 4 2
2 5 2
10 6 3
21 3 2
3
5 9 1
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...