제출 #1062201

#제출 시각아이디문제언어결과실행 시간메모리
1062201oscar1fSparklers (JOI17_sparklers)C++17
0 / 100
1 ms348 KiB
#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() 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()); } 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); 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...