답안 #24921

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
24921 2017-06-17T07:21:33 Z kdh9949 케이크 (JOI13_cake) C++14
10 / 100
1500 ms 12440 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n, mn = 2e9, mi;
int a[900010];
ll cans, ans[300010];

void f(int s, int e, int x){
	if(e - s - 1 == n - 1){ ans[s > n ? s - n : s] = cans + a[s]; return; }
	if(x){
		if(a[s] > a[e - 1]){
			cans += a[s];
			f(s - 1, e, 0);
			cans -= a[s];
		}
		if(a[s + 1] < a[e]){
			cans += a[e];
			f(s, e + 1, 0);
			cans -= a[e];
		}
	}
	else{
		if(a[s] > a[e - 1]) f(s - 1, e, 1);
		if(a[s + 1] < a[e]) f(s, e + 1, 1);
	}
}

void g(int s, int e, int x){
	if(e - s - 1 == n) return;
	if(x){
		if(a[s] > a[e]){
			ans[mi] += a[s];
			g(s - 1, e, 0);	
		}
		else{
			ans[mi] += a[e];
			g(s, e + 1, 0);
		}
	}
	else{
		if(a[s] > a[e]) g(s - 1, e, 1);
		else g(s, e + 1, 1);
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", a + i);
		a[n + i] = a[2 * n + i] = a[i];
		if(a[i] < mn){
			mn = a[i];
			mi = i;
		}
	}
	ans[mi] = mn;
	if(n % 2) cans = mn;
	f(n + mi - 1, n + mi + 1, !(n % 2));
	g(n + mi - 1, n + mi + 1, 0);
	for(int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
}

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:48:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
cake.cpp:50:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", a + i);
                     ^
# 결과 실행 시간 메모리 Grader output
1 Correct 109 ms 7988 KB Output is correct
2 Correct 109 ms 7992 KB Output is correct
3 Correct 79 ms 7992 KB Output is correct
4 Correct 103 ms 7988 KB Output is correct
5 Correct 73 ms 7992 KB Output is correct
6 Correct 99 ms 7988 KB Output is correct
7 Correct 79 ms 7984 KB Output is correct
8 Correct 86 ms 7992 KB Output is correct
9 Correct 0 ms 7880 KB Output is correct
10 Correct 0 ms 7880 KB Output is correct
11 Correct 0 ms 7880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1500 ms 12440 KB Execution timed out
2 Halted 0 ms 0 KB -