Submission #254189

# Submission time Handle Problem Language Result Execution time Memory
254189 2020-07-29T13:29:42 Z shayan_p Homecoming (BOI18_homecoming) C++14
100 / 100
189 ms 118140 KB
// 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 time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 20344 KB Output is correct
2 Correct 3 ms 896 KB Output is correct
3 Correct 180 ms 118136 KB Output is correct
4 Correct 2 ms 1408 KB Output is correct
5 Correct 9 ms 3416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 640 KB Output is correct
7 Correct 1 ms 640 KB Output is correct
8 Correct 1 ms 512 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 516 KB Output is correct
11 Correct 42 ms 20344 KB Output is correct
12 Correct 3 ms 896 KB Output is correct
13 Correct 180 ms 118136 KB Output is correct
14 Correct 2 ms 1408 KB Output is correct
15 Correct 9 ms 3416 KB Output is correct
16 Correct 189 ms 118140 KB Output is correct
17 Correct 77 ms 27932 KB Output is correct
18 Correct 149 ms 42036 KB Output is correct
19 Correct 125 ms 66740 KB Output is correct
20 Correct 135 ms 101264 KB Output is correct
21 Correct 129 ms 64228 KB Output is correct