Submission #503467

#TimeUsernameProblemLanguageResultExecution timeMemory
503467ymmCandies (JOI18_candies)C++17
100 / 100
4944 ms7760 KiB
/// /// What would happen if we used assembly language for CP? /// Sorry, that was a strange thing to ask. /// #include <bits/stdc++.h> #define Loop(x,l,r) for(ll x = ll(l); x < ll(r); ++x) #define LoopR(x,l,r) for(ll x = ll(r)-1; x >= ll(l); --x) #define Kill(x) exit((cout << (x) << '\n', 0)) typedef long long ll; typedef std::pair<int,int> pii; typedef std::pair<ll,ll> pll; using namespace std; #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx") #define max(x,y) ((x)>(y)?(x):(y)) const int N = 200'010; double dp[4][N]; int a[N]; int n; int main() { cin.tie(0) -> sync_with_stdio(false); cin >> n; Loop(i,0,n) cin >> a[i]; Loop(_,0,n) { const double x = a[_]; const int i = (_+1)&3; const int r = (_+2)/2; switch(i){ case 0: Loop(j,1,r) dp[0][j] = max(dp[3][j], dp[2][j-1]+x); break; case 1: Loop(j,1,r) dp[1][j] = max(dp[0][j], dp[3][j-1]+x); break; case 2: Loop(j,1,r) dp[2][j] = max(dp[1][j], dp[0][j-1]+x); break; case 3: Loop(j,1,r) dp[3][j] = max(dp[2][j], dp[1][j-1]+x); break; } dp[i][0] = max(dp[(i+3)&3][0], x); } Loop(i,0,(n+1)/2) cout << (ll)dp[n&3][i] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...