Submission #64004

#TimeUsernameProblemLanguageResultExecution timeMemory
64004Just_Solve_The_ProblemHomecoming (BOI18_homecoming)C++11
13 / 100
1078 ms110236 KiB
#include "homecoming.h" #include <bits/stdc++.h> using namespace std; #define ll long long const int N = (int)2e6 + 7; const ll linf = (ll)1e18 + 7; ll pref[N + N]; ll dp[N][2][2]; ll get(int l, int r) { if (!l) return pref[r]; return pref[r] - pref[l - 1]; } ll solve(int n, int k, int a[], int b[]) { pref[0] = b[0]; for (int i = 0; i < n + n; i++) { pref[i + 1] = pref[i] + b[(i + 1) % n]; } for (int i = 0; i < N; i++) for (int j = 0; j < 2; j++) for (int l = 0; l < 2; l++) dp[i][j][l] = -linf; dp[0][1][1] = a[0] - pref[k - 1]; dp[0][0][0] = 0; for (int i = 1; i < n; i++) { for (int j = 0; j < 2; j++) { dp[i][0][j] = max(dp[i - 1][0][j], dp[i - 1][1][j]); if (j == 0 || i + k - 1 < n) { dp[i][1][j] = max(dp[i - 1][0][j] + a[i] - get(i, i + k - 1), dp[i - 1][1][j] + a[i] - b[(i + k - 1) % n]); } else { dp[i][1][j] = max(dp[i - 1][0][j] + a[i] - get(i, n - 1), dp[i - 1][1][j] + a[i]); } // cout << i << ' ' << j << ' ' << dp[i][0][j] << ' ' << dp[i][1][j] << endl; } } ll ans = 0; for (int i = 0; i < 2; i++) for (int j = 0; j < 2; j++) ans = max(ans, dp[n - 1][i][j]); 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...