Submission #254189

#TimeUsernameProblemLanguageResultExecution timeMemory
254189shayan_pHomecoming (BOI18_homecoming)C++14
100 / 100
189 ms118140 KiB
// And you curse yourself for things you never done #include<bits/stdc++.h> #define F first #define S second #define PB push_back #define sz(s) int((s).size()) #define bit(n,k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn = 2e6 + 10, mod = 1e9 + 7; const ll inf = 1e18; int a[maxn], b[maxn]; ll dp[maxn][2], A[maxn], B[maxn]; ll solve(int n, int k, int *a, int *b){ for(int i = 0; i < n; i++) A[i] = a[i] - b[i]; ll sm = 0; for(int i = 1; i <= k-1; i++) sm+= a[n-i]; for(int i = 0; i < n; i++) B[i] = -sm, sm+= a[i], sm-= a[(i + n - k + 1) % n]; ll ans = 0; for(int w = 0; w < 2; w++){ if(w == 0) dp[0][0] = 0, dp[0][1] = -inf; else dp[0][0] = -inf, dp[0][1] = A[0]; for(int i = 1; i < n; i++){ dp[i][1] = max(dp[i-1][1], dp[i-1][0]) + A[i]; dp[i][0] = max(dp[i-1][0], dp[i-1][1] + B[i]); } for(int w2 = 0; w2 < 2; w2++) ans = max(ans, dp[n-1][w2] + ((w2 == 1 && w == 0) ? B[0] : 0)); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...