Submission #1063602

# Submission time Handle Problem Language Result Execution time Memory
1063602 2024-08-17T21:10:36 Z oscar1f Sparklers (JOI17_sparklers) C++17
100 / 100
278 ms 17028 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int TAILLE_MAX=100*1000+5,INFINI=1000*1000*1000;
int nbVal,posInit,tempsInit;
int val[TAILLE_MAX];

void afficher(vector<int> v) {
    for (int i:v) {
        cout<<i<<" ";
    }
    cout<<endl;
}

vector<int> calcCumu(vector<int> v) {
    vector<int> ans={0};
    int somCour=0;
    for (int i:v) {
        somCour+=i;
        ans.push_back(somCour);
    }
    return ans;
}

bool verif(int temps) {
    //cout<<temps<<endl;
    vector<int> listeGau,listeDro;
    for (int i=posInit;i>1;i--) {
        listeGau.push_back(2*temps-val[i]+val[i-1]);
    }
    for (int i=posInit+1;i<=nbVal;i++) {
        listeDro.push_back(2*temps-val[i]+val[i-1]);
    }
    vector<int> cumuGau=calcCumu(listeGau),cumuDro=calcCumu(listeDro);
    //afficher(cumuGau);
    //afficher(cumuDro);
    int tailleGau=cumuGau.size(),tailleDro=cumuDro.size();
    /*for (int i:cumuGau) {
        for (int j:cumuDro) {
            if (i+j>=0) {
                cout<<1<<" ";
            }
            else {
                cout<<0<<" ";
            }
        }
        cout<<endl;
    } 
    cout<<endl;*/
    int minCour=INFINI*INFINI,maxCour=-INFINI*INFINI,posMin=0,posMax=0;
    vector<pair<int,int>> minJusquaGau,maxJusquaGau,minDepuisGau,maxDepuisGau;
    for (int i=0;i<tailleGau;i++) {
        if (minCour>cumuGau[i]) {
            minCour=cumuGau[i];
            posMin=i;
        }
        if (maxCour<cumuGau[i]) {
            maxCour=cumuGau[i];
            posMax=i;
        }
        minJusquaGau.push_back({minCour,posMin});
        maxJusquaGau.push_back({maxCour,posMax});
    }
    minCour=INFINI*INFINI;
    maxCour=-INFINI*INFINI;
    for (int i=tailleGau-1;i>=0;i--) {
        if (minCour>cumuGau[i]) {
            minCour=cumuGau[i];
            posMin=i;
        }
        if (maxCour<cumuGau[i]) {
            maxCour=cumuGau[i];
            posMax=i;
        }
        minDepuisGau.push_back({minCour,posMin});
        maxDepuisGau.push_back({maxCour,posMax});
    }
    reverse(minDepuisGau.begin(),minDepuisGau.end());
    reverse(maxDepuisGau.begin(),maxDepuisGau.end());

    minCour=INFINI*INFINI;
    maxCour=-INFINI*INFINI;
    vector<pair<int,int>> minJusquaDro,maxJusquaDro,minDepuisDro,maxDepuisDro;
    for (int i=0;i<tailleDro;i++) {
        if (minCour>cumuDro[i]) {
            minCour=cumuDro[i];
            posMin=i;
        }
        if (maxCour<cumuDro[i]) {
            maxCour=cumuDro[i];
            posMax=i;
        }
        minJusquaDro.push_back({minCour,posMin});
        maxJusquaDro.push_back({maxCour,posMax});
    }
    minCour=INFINI*INFINI;
    maxCour=-INFINI*INFINI;
    for (int i=tailleDro-1;i>=0;i--) {
        if (minCour>cumuDro[i]) {
            minCour=cumuDro[i];
            posMin=i;
        }
        if (maxCour<cumuDro[i]) {
            maxCour=cumuDro[i];
            posMax=i;
        }
        minDepuisDro.push_back({minCour,posMin});
        maxDepuisDro.push_back({maxCour,posMax});
    }
    reverse(minDepuisDro.begin(),minDepuisDro.end());
    reverse(maxDepuisDro.begin(),maxDepuisDro.end());

    //cout<<"deb OK"<<endl;
    int valMinGau=minJusquaGau.back().first,valMaxGau=maxJusquaGau.back().first,posMaxGau=maxJusquaGau.back().second;
    int valMinDro=minJusquaDro.back().first,valMaxDro=maxJusquaDro.back().first,posMaxDro=maxJusquaDro.back().second;
    //cout<<"!"<<posMaxGau<<" "<<posMaxDro<<endl;
    if (valMinGau+valMaxDro<0 or valMinDro+valMaxGau<0) {
        return false;
    }
    int posGau=posMaxGau-1,posDro=posMaxDro-1;
    while (posGau>=0 and posDro>=0) {
        if (maxJusquaGau[posGau].first+minJusquaDro[posDro].first>=0) {
            posGau=maxJusquaGau[posGau].second-1;
        }
        else if (maxJusquaDro[posDro].first+minJusquaGau[posGau].first>=0) {
            posDro=maxJusquaDro[posDro].second-1;
        }
        else {
            return false;
        }
    } 
    //cout<<"mid OK"<<endl;
    /*for (auto i:maxDepuisGau) {
        cout<<i.first<<" "<<i.second<<"\t";
    } 
    cout<<endl;
    for (auto i:maxDepuisDro) {
        cout<<i.first<<" "<<i.second<<"\t";
    }
    cout<<endl;*/

    posGau=posMaxGau+1;
    posDro=posMaxDro+1;
    while (posGau<tailleGau and posDro<tailleDro) {
        //cout<<posGau<<" "<<posDro<<endl;
        if (maxDepuisGau[posGau].first+minDepuisDro[posDro].first>=0) {
            posGau=maxDepuisGau[posGau].second+1;
        }
        else if (maxDepuisDro[posDro].first+minDepuisGau[posGau].first>=0) {
            posDro=maxDepuisDro[posDro].second+1;
        }
        else {
            return false;
        }
    } 
    //cout<<"fin OK"<<endl;
    return true;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>nbVal>>posInit>>tempsInit;
    for (int i=1;i<=nbVal;i++) {
        cin>>val[i];
    }
    verif(23437500);
    int deb=0,fin=INFINI,mid;
    while (deb!=fin) {
        mid=(deb+fin)/2;
        if (verif(mid)) {
            fin=mid;
        }
        else {
            deb=mid+1;
        }
    }
    cout<<(deb+tempsInit-1)/tempsInit<<endl;
    return 0;
}
 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 3 ms 624 KB Output is correct
33 Correct 3 ms 616 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 600 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 3 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 2 ms 604 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 2 ms 348 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 3 ms 624 KB Output is correct
33 Correct 3 ms 616 KB Output is correct
34 Correct 2 ms 348 KB Output is correct
35 Correct 2 ms 600 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 600 KB Output is correct
39 Correct 2 ms 348 KB Output is correct
40 Correct 3 ms 616 KB Output is correct
41 Correct 142 ms 7692 KB Output is correct
42 Correct 8 ms 912 KB Output is correct
43 Correct 43 ms 2728 KB Output is correct
44 Correct 278 ms 15596 KB Output is correct
45 Correct 214 ms 12368 KB Output is correct
46 Correct 262 ms 15748 KB Output is correct
47 Correct 273 ms 15864 KB Output is correct
48 Correct 213 ms 12284 KB Output is correct
49 Correct 203 ms 13976 KB Output is correct
50 Correct 241 ms 12300 KB Output is correct
51 Correct 266 ms 16016 KB Output is correct
52 Correct 206 ms 12784 KB Output is correct
53 Correct 234 ms 17028 KB Output is correct
54 Correct 204 ms 12784 KB Output is correct
55 Correct 214 ms 12128 KB Output is correct
56 Correct 260 ms 16004 KB Output is correct
57 Correct 207 ms 13416 KB Output is correct
58 Correct 232 ms 12420 KB Output is correct
59 Correct 205 ms 11432 KB Output is correct
60 Correct 225 ms 12788 KB Output is correct
61 Correct 192 ms 11436 KB Output is correct
62 Correct 239 ms 16056 KB Output is correct
63 Correct 192 ms 15340 KB Output is correct
64 Correct 207 ms 12168 KB Output is correct
65 Correct 206 ms 12332 KB Output is correct
66 Correct 209 ms 12180 KB Output is correct
67 Correct 207 ms 12328 KB Output is correct
68 Correct 215 ms 12792 KB Output is correct
69 Correct 207 ms 12820 KB Output is correct