답안 #1062209

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1062209 2024-08-16T21:31:43 Z oscar1f Sparklers (JOI17_sparklers) C++17
0 / 100
0 ms 352 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];

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 calc(vector<pair<int,int>> bonGau,vector<pair<int,int>> bonDro) {
    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() or bonDro.empty()) {
            return true;
        }
        else if (somCour+bonGau.back().second+bonDro.back().first>=0 or somCour+bonDro.back().second+bonGau.back().first>=0) {
            return true;
        }
        else {
            return false;
        }
    }
    return (bonGau.empty() and bonDro.empty());
}

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);
    if (calc(bonGau,bonDro)!=calc(bonDro,bonGau)) {
        while (1>0) {
            listeGau.pop_back();
        }
    }
    return (calc(bonGau,bonDro) or calc(bonDro,bonGau)); 
}

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;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 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 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 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 344 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 352 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 344 KB Output isn't correct
8 Halted 0 ms 0 KB -