# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
24920 |
2017-06-17T07:15:23 Z |
kdh9949 |
케이크 (JOI13_cake) |
C++14 |
|
1500 ms |
12444 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;
}
}
cans = ans[mi] = 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);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
7992 KB |
Output is correct |
2 |
Incorrect |
106 ms |
7992 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1500 ms |
12444 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |