Submission #996318

#TimeUsernameProblemLanguageResultExecution timeMemory
996318jcelinSparklers (JOI17_sparklers)C++14
0 / 100
1 ms452 KiB
#include<bits/stdc++.h> using namespace std; #define X first #define Y second #define PB push_back #define PPB pop_back #define all(x) (x).begin(), (x).end() typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; typedef long long ll; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef vector<pll> vpll; typedef long double ld; const int MAXN = 47; const int logo = 20; const int off = 1 << logo; const int trsz = off << 1; const int mod = 1e9 + 7; const ll inf = 1e18 + 7; const ll INF = 1e18 + 7; ll x[MAXN], n, k, t; vll lef, rig; vpll L, R, nl, nr; bool okej(ll poc, vpll &vec){ for(auto &y : vec){ if(poc + y.Y < 0) return 0; poc += y.X; } return poc >= 0; } bool check(ll mid){ lef.clear(); rig.clear(); L.clear(); R.clear(); nl.clear(); nr.clear(); ll sum = 0; for(int i=k; i<n; i++) rig.PB((ll)2 * mid * t - (ll)(x[i + 1] - (ll)x[i]) / 2), sum += rig.back(); for(int i=1; i<k; i++) lef.PB((ll)2 * mid * t - (ll)(x[i + 1] - (ll)x[i]) / 2), sum += lef.back(); reverse(all(lef)); ll csu = 0, mi = 0; int ls = -1; for(int i=0; i<(int)rig.size(); i++){ csu += rig[i]; mi = min(mi, csu); if(csu >= 0){ R.PB({csu, mi}); csu = mi = 0; ls = i; } } csu = mi = 0; for(int i=(int)rig.size() - 1; i>ls; i--){ csu -= rig[i]; mi = min(mi, csu); if(csu >= 0){ nr.PB({csu, mi}); csu = mi = 0; } } csu = 0, mi = 0; ls = -1; for(int i=0; i<(int)lef.size(); i++){ csu += lef[i]; mi = min(mi, csu); if(csu >= 0){ L.PB({csu, mi}); csu = mi = 0; ls = i; } } csu = mi = 0; for(int i=(int)lef.size() - 1; i>ls; i--){ csu -= lef[i]; mi = min(mi, csu); if(csu >= 0){ nl.PB({csu, mi}); csu = mi = 0; } } int li = 0, ri = 0; csu = 0; while(1){ pll c1 = {-inf, -inf}, c2 = {-inf, -inf}; if(li < (int)L.size()) c1 = L[li]; if(ri < (int)R.size()) c2 = R[ri]; if(c1.X == -inf and c2.X == -inf) break; if(csu + c1.Y >= 0){ csu += c1.X; li++; continue; } if(csu + c2.Y >= 0){ csu += c2.X; ri++; continue; } return 0; } csu = sum; li = ri = 0; swap(L, nl); swap(R, nr); while(1){ pll c1 = {-inf, -inf}, c2 = {-inf, -inf}; if(li < (int)L.size()) c1 = L[li]; if(ri < (int)R.size()) c2 = R[ri]; if(c1.X == -inf and c2.X == -inf) break; if(csu + c1.Y >= 0){ csu += c1.X; li++; continue; } if(csu + c2.Y >= 0){ csu += c2.X; ri++; continue; } return 0; } return 1; } void solve(){ cin >> n >> k >> t; for(int i=1; i<=n; i++) cin >> x[i], x[i] *= 2; int lo = 1, hi = ((1e9 + 1) / t) + 1, ret = -1; while(lo <= hi){ int mid = (lo + hi) / 2; if(check(mid)) hi = mid - 1, ret = mid; else lo = mid + 1; } cout << ret << "\n"; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int tt = 1; //cin >> t; while(tt--) solve(); return 0; } /* -15708 2615 22272 -6638 -35674 -50958 41359 -1318 -33710 -40703 4522 12061 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...