이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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]);
}
컴파일 시 표준 에러 (stderr) 메시지
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 |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |