Submission #864576

#TimeUsernameProblemLanguageResultExecution timeMemory
864576manizareSparklers (JOI17_sparklers)C++14
0 / 100
1 ms4596 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #define pb push_back #define F first #define S second #define all(a) a.begin(),a.end() #define pii pair <int,int> #define Pii pair< pii , pii > #define int long long using namespace std ; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxn = 6e5 + 10 , sq = 3 , maxq = 1e7 + 1 , inf = 1e18 + 10 , mod= 998244353 ,lg = 20 ; int n ,t , k; vector <int> a , b ; int x[maxn] ; int pa[maxn] , pb[maxn] , ma[maxn] , mb[maxn] ; int sl(){ vector <int> va , vb ; va.pb(0);vb.pb(0); for(int i = 1; i < a.size() ; i++){ pa[i] = pa[i-1] + a[i] ; if(pa[i] > pa[va.back()]){ ma[va.size()-1] = 0 ; for(int j = va.back() + 1 ; j < i ; j++){ ma[va.size()-1] = min(ma[va.size()-1] , pa[j] - pa[va.back()]) ; } va.pb(i) ; } } for(int i = 1; i < b.size() ; i++){ pb[i] = pb[i-1] + b[i] ; if(pb[i] > pb[vb.back()]){ mb[vb.size()-1] = 0 ; for(int j = vb.back() + 1 ; j < i ; j++){ mb[vb.size()-1] = min(mb[vb.size()-1] , pb[j] - pb[vb.back()]) ; } vb.pb(i) ; } } int id1 = 0 , id2 =0 , val = 0 ; while(1){ if(id1!=va.size()-1 && pa[va[id1]]+pb[vb[id2]]+ma[id1] >=0 ){ id1++; continue ; } if(id2!=vb.size()-1 && pa[va[id1]]+pb[vb[id2]]+mb[id2] >= 0){ id2++; continue ; } break ; } if(id1!=va.size()-1 || id2 != vb.size()-1){ return 0 ; } id1 = va[id1] + 1 ; id2 = vb[id2] + 1 ; vector<int> vec , vec2 ; for(int i =id1 ; i < a.size() ; i++)vec.pb(a[i]) ; for(int i =id2 ; i < b.size() ; i++)vec.pb(b[i]) ; for(int i =id2 ; i < b.size() ; i++)vec2.pb(b[i]) ; for(int i =id1 ; i < a.size() ; i++)vec2.pb(a[i]) ; int sm = pa[id1-1] + pb[id2-1] ; bool ok1 =1 ,ok2 =1 ; for(int i =0 ; i < vec.size() ;i++){ if(sm > 1e9)break ; sm += vec[i] ; if(sm < 0)ok1 =0 ; } sm =pa[id1-1] +pb[id2-1] ; for(int i= 0 ; i < vec2.size() ; i++){ if(sm > 1e9)break ; sm+=vec2[i] ; if(sm < 0)ok2 =0 ; } return ok1|ok2 ; } bool ch(int z){ a.clear();b.clear(); a.pb(0); b.pb(0) ; a.pb(t*2*z); for(int i = k+1; i <= n ; i++){ a.pb(-(x[i] - x[i-1])); a.pb(t*2*z) ; } for(int i = k-1 ; i >= 1; i--){ b.pb(-(x[i+1] - x[i])); b.pb(t*2*z) ; } return sl() ; } signed main() { ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ; cin >> n >> k >> t ; for(int i = 1; i <= n ; i++){ cin >> x[i] ; } int l = 0 , r = 8e5 + 1 ; while(r-l>1){ int mid = (l+r)/2 ; if(ch(mid) == 1)r= mid ; else l = mid ; } cout << r << "\n"; } /* */

Compilation message (stderr)

sparklers.cpp: In function 'long long int sl()':
sparklers.cpp:21:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(int i = 1; i < a.size() ; i++){
      |                  ~~^~~~~~~~~~
sparklers.cpp:31:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 1; i < b.size() ; i++){
      |                  ~~^~~~~~~~~~
sparklers.cpp:43:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     if(id1!=va.size()-1 && pa[va[id1]]+pb[vb[id2]]+ma[id1] >=0 ){
      |        ~~~^~~~~~~~~~~~~
sparklers.cpp:47:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     if(id2!=vb.size()-1 && pa[va[id1]]+pb[vb[id2]]+mb[id2] >= 0){
      |        ~~~^~~~~~~~~~~~~
sparklers.cpp:53:9: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   if(id1!=va.size()-1 || id2 != vb.size()-1){
      |      ~~~^~~~~~~~~~~~~
sparklers.cpp:53:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   if(id1!=va.size()-1 || id2 != vb.size()-1){
      |                          ~~~~^~~~~~~~~~~~~~
sparklers.cpp:59:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i =id1 ; i < a.size() ; i++)vec.pb(a[i]) ;
      |                    ~~^~~~~~~~~~
sparklers.cpp:60:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |   for(int i =id2 ; i < b.size() ; i++)vec.pb(b[i]) ;
      |                    ~~^~~~~~~~~~
sparklers.cpp:61:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |   for(int i =id2 ; i < b.size() ; i++)vec2.pb(b[i]) ;
      |                    ~~^~~~~~~~~~
sparklers.cpp:62:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for(int i =id1 ; i < a.size() ; i++)vec2.pb(a[i]) ;
      |                    ~~^~~~~~~~~~
sparklers.cpp:65:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i =0 ; i < vec.size() ;i++){
      |                  ~~^~~~~~~~~~~~
sparklers.cpp:71:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |   for(int i=  0 ; i < vec2.size() ; i++){
      |                   ~~^~~~~~~~~~~~~
sparklers.cpp:41:26: warning: unused variable 'val' [-Wunused-variable]
   41 |   int id1 = 0 , id2 =0 , val = 0 ;
      |                          ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...