Submission #768683

#TimeUsernameProblemLanguageResultExecution timeMemory
768683raysh07Candies (JOI18_candies)C++17
100 / 100
2435 ms25340 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define INF (int)1e18 #define f first #define s second mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count()); int n; const int N = 2e5 + 69; int a[N]; vector<vector<int>> Build(int l, int r){ int yo = (r - l + 1); int z = (yo + 1) / 2; vector<vector<int>> dp(z + 1, vector<int>(4, -INF)); if (l == r){ dp[0][0] = 0; dp[1][3] = a[l]; return dp; } int m = (l + r) / 2; auto dp1 = Build(l, m); auto dp2 = Build(m + 1, r); // for (auto x : dp1){ // for (auto y : x){ // cout << y << " "; // } // cout << "\n"; // } // cout << "\n"; // for (auto x : dp2){ // for (auto y : x){ // cout << y << " "; // } // cout << "\n"; // } // cout << "\n"; for (int i = 0; i <= z; i++){ for (int b = 0; b < 2; b++){ for (int c = 0; c < 2; c++){ for (int d = 0; d < 2; d++){ for (int e = 0; e < 2; e++){ if (c && d) continue; int p = b + 2 * e; int p1 = b + 2 * c; int p2 = d + 2 * e; int lo = 0; int hi = i; while (hi - lo > 2){ int m1 = (2 * lo + hi) / 3; int m2 = (lo + 2 * hi) / 3; if (m2 >= dp1.size()) { hi = m2; continue; } if ((i - m1) >= dp2.size()){ lo = m1; continue; } int v1 = dp1[m1][p1] + dp2[i - m1][p2]; int v2 = dp1[m2][p1] + dp2[i - m2][p2]; if (v1 > v2) hi = m2; else lo = m1; } for (int m1 = lo; m1 <= hi; m1++){ if (m1 >= dp1.size() || (i - m1) >= dp2.size()) continue; int v1 = dp1[m1][p1] + dp2[i - m1][p2]; dp[i][p] = max(dp[i][p], v1); } } } } } } return dp; } void Solve() { cin >> n; for (int i = 1; i <= n; i++){ cin >> a[i]; } auto dp = Build(1, n); for (int i = 1; i < dp.size(); i++){ int mx = 0; for (int j = 0; j < 4; j++) mx = max(mx, dp[i][j]); cout << mx << "\n"; } } int32_t main() { auto begin = std::chrono::high_resolution_clock::now(); ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; for(int i = 1; i <= t; i++) { //cout << "Case #" << i << ": "; Solve(); } auto end = std::chrono::high_resolution_clock::now(); auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin); cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; return 0; }

Compilation message (stderr)

candies.cpp: In function 'std::vector<std::vector<long long int> > Build(long long int, long long int)':
candies.cpp:60:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                             if (m2 >= dp1.size()) {
      |                                 ~~~^~~~~~~~~~~~~
candies.cpp:64:42: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |                             if ((i - m1) >= dp2.size()){
      |                                 ~~~~~~~~~^~~~~~~~~~~~~
candies.cpp:77:36: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |                             if (m1 >= dp1.size() || (i - m1) >= dp2.size()) continue;
      |                                 ~~~^~~~~~~~~~~~~
candies.cpp:77:62: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |                             if (m1 >= dp1.size() || (i - m1) >= dp2.size()) continue;
      |                                                     ~~~~~~~~~^~~~~~~~~~~~~
candies.cpp: In function 'void Solve()':
candies.cpp:100:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  100 |     for (int i = 1; i < dp.size(); i++){
      |                     ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...