답안 #170416

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170416 2019-12-25T06:37:21 Z Retro3014 Homecoming (BOI18_homecoming) C++17
100 / 100
210 ms 118216 KB
#include <bits/stdc++.h>
#include "homecoming.h"

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 2000000;

ll dp[2][2], A[MAX_N+1], B[MAX_N+1], SA[MAX_N+1], SB[MAX_N+1];
ll ndp[2][2];

int N, K;
ll sumA(int x, int y){
	if(x==0){
		return SA[y];
	}
	if(x<=y){
		return SA[y]-SA[x-1];
	}else{
		return SA[N-1]-SA[x-1]+SA[y];
	}
}
ll sumB(int x, int y){
	if(x==0)	return SB[y];
	if(x<=y){
		return SB[y]-SB[x-1];
	}else{
		return SB[N-1]-SB[x-1]+SB[y];
	}	
}

long long int solve(int n, int k, int *C, int *D){
	N = n; K = k;
	for(int i=0; i<N; i++){
		A[i] = (ll)C[i];
		B[i] = (ll)D[i];
		if(i!=0){
			SA[i] = SA[i-1] + A[i];
			SB[i] = SB[i-1] + B[i];
		}else{
			SA[i] = A[i]; SB[i] = B[i];
		}
	}
	dp[0][0] = 0;
	dp[0][1] = 0;
	dp[1][0] = A[0] - sumB(0, K-1);
	dp[1][1] = A[0] - B[K-1];
	for(int i=1; i<N; i++){
		for(int j=0; j<2; j++){
			ndp[0][j] = max(dp[0][j], dp[1][j]);
			ndp[1][j] = max(dp[1][j] + A[i] - B[(i+K-1)%N], dp[0][j] + A[i] - sumB(i, (i+K-1)%N));
			dp[0][j] = ndp[0][j]; dp[1][j] = ndp[1][j];
		}
	}
	return max(dp[0][0], dp[1][1]);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 29432 KB Output is correct
2 Correct 4 ms 1016 KB Output is correct
3 Correct 208 ms 118216 KB Output is correct
4 Correct 4 ms 1400 KB Output is correct
5 Correct 25 ms 3408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 3 ms 676 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 55 ms 29432 KB Output is correct
12 Correct 4 ms 1016 KB Output is correct
13 Correct 208 ms 118216 KB Output is correct
14 Correct 4 ms 1400 KB Output is correct
15 Correct 25 ms 3408 KB Output is correct
16 Correct 210 ms 118076 KB Output is correct
17 Correct 89 ms 28060 KB Output is correct
18 Correct 157 ms 41992 KB Output is correct
19 Correct 149 ms 66772 KB Output is correct
20 Correct 161 ms 101112 KB Output is correct
21 Correct 168 ms 64300 KB Output is correct