Submission #714515

# Submission time Handle Problem Language Result Execution time Memory
714515 2023-03-24T21:20:26 Z MohammadAghil Candies (JOI18_candies) C++17
0 / 100
199 ms 524288 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
 using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
     #define per(i,r,l) for(int i = (r); i >= (l); i--)
       #define rep(i,l,r) for(int i = (l); i < (r); i++)
          #define all(x) begin(x), end(x)
             #define sz(x) (int)(x).size()
                 #define pb push_back
                     #define ss second
                          #define ff first
                                  void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     #ifndef ONLINE_JUDGE
          #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
          freopen("inp.txt", "r", stdin);
          freopen("out.txt", "w", stdout);
     #else
          #define er(args ...) 0
     #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 998244353, maxn = 1000 + 5, sq = 400, ln = maxn/sq + 5, lg = 22, inf = ll(1e18) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}

int a[maxn];

vector<ll> comb(vector<ll> a, vector<ll> b){
     vector<ll> res(sz(a) + sz(b) - 1);
     rep(i,0,sz(res)){
          int l = max(0, i - sz(b) + 1);
          int r = min(sz(a)-1, i) + 1;
          auto get = [&](int x){
               return a[x] + b[i - x];
          };
          while(l + 1 < r){
               int mid = (l + r)>>1;
               ll w = get(mid) - get(mid-1);
               if(w > 0) l = mid;
               else r = mid;
          }
          res[i] = get(l);
     }
     return res;
}

vector<vector<vector<ll>>> slv(int l, int r){
     if(l + 1 == r){
          return {{{0, -inf}, {-inf, -inf}}, {{-inf, -inf}, {-inf, a[l]}}};
     }
     int mid = (l + r)>>1;
     auto resl = slv(l, mid), resr = slv(mid, r);
     int len = (r - l + 1)/2 + 1;
     vector<vector<vector<ll>>> res(2, vector<vector<ll>>(2));
     rep(i,0,2){
          rep(j,0,2){
               res[i][j] = comb(resl[i][0], resr[0][j]);
               rep(t,0,2){
                    vector<ll> tmp = comb(resl[i][t], resr[t^1][j]);
                    rep(k,0,sz(tmp)) res[i][j][k] = max(res[i][j][k], tmp[k]); 
               }
               res[i][j].resize(len);
          }
     }
     return res;
}

int main(){ IOS();
     int n; cin >> n;
     rep(i,0,n) cin >> a[i];
     auto res = slv(0, n);
     vector<ll> ans = res[0][0];
     rep(i,0,2) rep(j,0,2){
          rep(k,0,sz(ans)) ans[k] = max(ans[k], res[i][j][k]);
     }
     rep(i,1,((n+1)>>1)+1){
          cout << ans[i] << '\n';
     }
     return 0-0;
}

Compilation message

candies.cpp: In function 'void IOS()':
candies.cpp:19:18: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |           freopen("inp.txt", "r", stdin);
      |           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
candies.cpp:20:18: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |           freopen("out.txt", "w", stdout);
      |           ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 199 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 199 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -