Submission #157684

#TimeUsernameProblemLanguageResultExecution timeMemory
157684imyujinSparklers (JOI17_sparklers)C++17
100 / 100
124 ms7028 KiB
#include <bits/stdc++.h> using namespace std; typedef long long lint; typedef pair<lint, lint> pll; #define fi first #define se second const int MAXN = 100010; const int INF = 1 << 30; lint X[MAXN]; void solve(vector<lint> &v, vector<pll> &r, vector<pll> &x) { for(auto &a : v) { pll t = pll(a, max(-a, 0ll)); while(!r.empty() && t.fi < 0) { t.se = max(t.se, r.back().se - t.fi); t.fi += r.back().fi; r.pop_back(); } (t.fi >= 0 ? r : x).push_back(t); } } int main() { ios::sync_with_stdio(0); cin.tie(0); int N, K; lint T; cin >> N >> K >> T; for(int i = 1; i <= N; i++) cin >> X[i]; lint s = 0, e = INF; while(s < e) { lint m = (s + e) / 2; vector<lint> v1, v2; for(int i = 1; i < K; i++) v1.push_back(2 * T * m - X[i + 1] + X[i]); for(int i = N; i > K; i--) v2.push_back(2 * T * m - X[i] + X[i - 1]); vector<pll> r1, r2, x1, x2; solve(v1, r1, x1); solve(v2, r2, x2); /* printf("m = %lld\nv1 : ", m); for(auto a : v1) printf("%lld ", a); printf("\nv2 : "); for(auto a : v2) printf("%lld ", a); printf("\nr1 : "); for(auto a : r1) printf("(%lld, %lld) ", a.fi, a.se); printf("\nr2 : "); for(auto a : r2) printf("(%lld, %lld) ", a.fi, a.se); printf("\n"); */ lint t = 0; int p1 = int(r1.size()) - 1, p2 = int(r2.size()) - 1; while(p1 >= 0 || p2 >= 0) { if(p1 >= 0 && t >= r1[p1].se) t += r1[p1--].fi; else if(p2 >= 0 && t >= r2[p2].se) t += r2[p2--].fi; else break; } if(p1 >= 0 || p2 >= 0) { s = m + 1; continue; } p1 = p2 = 0; t = 0; for(auto a : v1) t += a; for(auto a : v2) t += a; while(p1 < x1.size() || p2 < x2.size()) { if(p1 < x1.size() && t - x1[p1].fi >= x1[p1].se) t -= x1[p1++].fi; else if(p2 < x2.size() && t - x2[p2].fi >= x2[p2].se) t -= x2[p2++].fi; else break; } if(p1 < x1.size() || p2 < x2.size()) s = m + 1; else e = m; } cout << s << "\n"; return 0; }

Compilation message (stderr)

sparklers.cpp: In function 'int main()':
sparklers.cpp:70:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(p1 < x1.size() || p2 < x2.size()) {
         ~~~^~~~~~~~~~~
sparklers.cpp:70:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(p1 < x1.size() || p2 < x2.size()) {
                           ~~~^~~~~~~~~~~
sparklers.cpp:71:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    if(p1 < x1.size() && t - x1[p1].fi >= x1[p1].se) t -= x1[p1++].fi;
       ~~~^~~~~~~~~~~
sparklers.cpp:72:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    else if(p2 < x2.size() && t - x2[p2].fi >= x2[p2].se) t -= x2[p2++].fi;
            ~~~^~~~~~~~~~~
sparklers.cpp:75:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(p1 < x1.size() || p2 < x2.size()) s = m + 1;
      ~~~^~~~~~~~~~~
sparklers.cpp:75:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(p1 < x1.size() || p2 < x2.size()) s = m + 1;
                        ~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...