제출 #412939

#제출 시각아이디문제언어결과실행 시간메모리
412939amoo_safarSparklers (JOI17_sparklers)C++17
50 / 100
2 ms512 KiB
// vaziat meshki-ghermeze ! #include <bits/stdc++.h> #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define debug(x) cerr << #x << " : " << x << '\n' using namespace std; typedef long long ll; typedef long double ld; typedef string str; typedef pair<ll, ll> pll; const ll Mod = 1000000007LL; const int N = 2e3 + 10; const ll Inf = 2242545357980376863LL; const ll Log = 30; int n, k; ll X[N]; ll psA[N], psB[N]; int dp[N][N]; bool Valid(vector<ll> psA, vector<ll> psB){ int sa = psA.size(), sb = psB.size(); int pa = 0, pb = 0; if(psA[sa - 1] + psB[sb - 1] < 0) return false; // cerr << "A :"; // for(auto X : psA) cerr << ' ' << X; // cerr << '\n'; // cerr << "B :"; // for(auto X : psB) cerr << ' ' << X; // cerr << '\n'; while((pa < sa - 1) || (pb < sb - 1)){ ll nw = psA[pa] + psB[pb]; if(nw < 0) return false; if(pa == sa - 1){ pb ++; continue; } if(pb == sb - 1){ pa ++; continue; } int des = pa; for(int nx = pa + 1; nx <= sa; nx ++){ if(psA[nx] + psB[pb] < 0) break; if(psA[pa] <= psA[nx]){ des = nx; break; } } if(des > pa){ pa ++; continue; } des = pb; for(int nx = pb + 1; nx <= sb; nx ++){ if(psA[pa] + psB[nx] < 0) break; if(psB[pb] <= psB[nx]){ des = nx; break; } } if(des > pb){ pb ++; continue; } //// return false; } return true; } bool Check(ll T){ if(T > 1000000000) return true; vector<ll> A = {T}, B = {}; for(int i = k + 1; i <= n; i++){ A.pb(X[i - 1] - X[i]); A.pb(T); } for(int i = k - 1; i >= 1; i--){ B.pb(X[i] - X[i + 1]); B.pb(T); } psA[0] = 0; for(int i = 1; i <= (int) A.size(); i++) psA[i] = psA[i - 1] + A[i - 1]; psB[0] = 0; for(int i = 1; i <= (int) B.size(); i++) psB[i] = psB[i - 1] + B[i - 1]; // cerr << "#"; // for(int i = 0; i <= (int) A.size(); i++) // cerr << ' ' << psA[i]; // cerr << '\n'; int idx = max_element(psA, psA + A.size() + 1) - psA; vector<ll> la, ra; for(int i = 0; i <= idx; i++) la.pb(psA[i]); for(int i = idx; i <= (int) A.size(); i++) ra.pb(psA[i]); // memset(dp, 0, sizeof dp); idx = max_element(psB, psB + B.size() + 1) - psB; vector<ll> lb, rb; for(int i = 0; i <= idx; i++) lb.pb(psB[i]); for(int i = idx; i <= (int) B.size(); i++) rb.pb(psB[i]); reverse(all(ra)); reverse(all(rb)); return Valid(la, lb) && Valid(ra, rb); } bool Check2(ll T){ if(T > 1000000000) return true; vector<ll> A, B; A = {T}; B = {}; for(int i = k + 1; i <= n; i++){ A.pb(X[i - 1] - X[i]); A.pb(T); } for(int i = k - 1; i >= 1; i--){ B.pb(X[i] - X[i + 1]); B.pb(T); } psA[0] = 0; for(int i = 1; i <= (int) A.size(); i++) psA[i] = psA[i - 1] + A[i - 1]; psB[0] = 0; for(int i = 1; i <= (int) B.size(); i++) psB[i] = psB[i - 1] + B[i - 1]; memset(dp, 0, sizeof dp); int sa = A.size(), sb = B.size(); dp[0][0] = 1; for(int i = 0; i <= sa; i++){ for(int j = 0; j <= sb; j++){ if(i + j == 0) continue; if(psA[i] + psB[j] < 0) continue; if(i) dp[i][j] |= dp[i - 1][j]; if(j) dp[i][j] |= dp[i][j - 1]; } } return dp[sa][sb]; } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll T; cin >> n >> k >> T; for(int i = 1; i <= n; i++) cin >> X[i]; int mid, L = -1, R = 1000000000; // int res = Check(2ll * T * 2); // debug(res); // exit(0); while(L + 1 < R){ mid = (L + R) >> 1; // if(Check(2ll * T * mid) != Check2(2ll * T * mid)){ // cerr << "!! " << mid << '\n'; // if(Check2(2ll * T * mid)) // assert(false); // } if(Check(2ll * T * mid)) R = mid; else L = mid; } cout << R << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...