# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
782547 | qwerasdfzxcl | 케이크 (JOI13_cake) | C++17 | 412 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map<int, ll> mp[300300];
int n, a[300300];
ll dfs(int l, int r, int typ = 0){
if (mp[l].find(r)!=mp[l].end()) return mp[l][r];
ll &ret = mp[l][r];
if (l==r){
if (typ) return ret = a[l];
return ret = 0;
}
if (a[l] > a[r]){
int nl = l+1;
if (nl > n) nl = 1;
return ret = ((typ)?a[l]:0) + dfs(nl, r, typ^1);
}
int nr = r-1;
if (nr < 1) nr = n;
return ret = ((typ)?a[r]:0) + dfs(l, nr, typ^1);
}
int main(){
scanf("%d", &n);
for (int i=1;i<=n;i++) scanf("%d", a+i);
for (int i=1;i<=n;i++){
int l = i+1, r = i-1;
if (l>n) l = 1;
if (r<1) r = n;
printf("%lld\n", a[i] + dfs(l, r, 0));
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |