답안 #105921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
105921 2019-04-15T17:42:15 Z xiaowuc1 Hacker (BOI15_hac) C++14
0 / 100
2 ms 384 KB
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef vector<vector<ll>> matrix;

int dp[1500000];

int getSum(int a, int b) {
	// want sum of elements from a index to b index, zero-indexed
	return dp[b+1] - dp[a];
}

void solve() {
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> dp[i];
		dp[i] += dp[i-1];
	}
	int sz = (n+1)/2;
	int ret = 0;
	for(int i = 0; i < n; i++) {
		int leftSum = 0;
		{
			// start at i, end at i + sz-1
			if(i+sz-1 < n) {
				leftSum = getSum(i, i+sz-1);
			}
			else {
				leftSum = getSum(i, n-1);
				int numOver = n-(i+sz);
				leftSum += getSum(0, numOver-1);
			}
		}
		int rightSum = 0;
		{
			// start at i-(sz-1), end at i
			if(i-(sz-1) >= 0) {
				rightSum = getSum(i-(sz-1), i);
			}
			else {
				rightSum = getSum(0, i);
				int numOver = sz-i-1;
				rightSum += getSum(n-1-numOver+1, n-1);
			}
		}
		ret = max(ret, min(leftSum, rightSum));
	}
	cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
	/*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
	*/
	solve();
}

Compilation message

hac.cpp: In function 'void solve()':
hac.cpp:23:15: warning: array subscript is below array bounds [-Warray-bounds]
  return dp[b+1] - dp[a];
         ~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -