Submission #1062138

# Submission time Handle Problem Language Result Execution time Memory
1062138 2024-08-16T19:44:13 Z oscar1f Sparklers (JOI17_sparklers) C++17
0 / 100
0 ms 504 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

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

vector<pair<int,int>> decompo(vector<int> v) {
    vector<pair<int,int>> ans;
    int somCour=0,minSom=0,taille=0;
    for (int i:v) {
        //cout<<i<<" ";
        somCour+=i;
        minSom=min(minSom,somCour);
        taille++;
        if (somCour>=0) {
            ans.push_back({somCour,minSom});
            taille=0;
            somCour=0;
            minSom=0;
        }
    }
    if (taille>0) {
        ans.push_back({somCour,minSom});
    }
    /*cout<<" : ";
    for (auto i:ans) {
        cout<<i.first<<" "<<i.second<<"   ";
    }
    cout<<endl;*/
    reverse(ans.begin(),ans.end());
    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<pair<int,int>> bonGau=decompo(listeGau),bonDro=decompo(listeDro);
    int somCour=0;
    while ((!bonGau.empty() and somCour+bonGau.back().second>=0) or (!bonDro.empty() and somCour+bonDro.back().second>=0)) {
        if (!bonGau.empty() and somCour+bonGau.back().second>=0 and bonGau.back().first>=0) {
            somCour+=bonGau.back().first;
            bonGau.pop_back();
        }
        else if (!bonDro.empty() and somCour+bonDro.back().second>=0 and bonDro.back().first>=0) {
            somCour+=bonDro.back().first;
            bonDro.pop_back();
        }
        else if (!bonGau.empty() and somCour+bonGau.back().second>=0) {
            somCour+=bonGau.back().first;
            bonGau.pop_back();
        }
        else {
            somCour+=bonDro.back().first;
            bonDro.pop_back();
        }
    }
    return (bonGau.empty() and bonDro.empty());
}

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];
    }
    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 0 ms 504 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 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 504 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 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 504 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 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -