답안 #295020

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
295020 2020-09-09T12:23:20 Z 반딧불(#5812) 케이크 (JOI13_cake) C++17
0 / 100
1353 ms 262148 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
ll arr[300002];
ll sum;

unordered_map<ll, ll> mp;

inline ll calc(int l, int r, bool c){
    if(l==r){
        if(!c) return 0;
        return arr[l];
    }
    ll tmp = ll(l)*1000000+ll(r);
    if(c) tmp *= -1;

    if(mp.find(tmp) != mp.end()) return mp[tmp];
    if(arr[l] < arr[r]) return mp[tmp] = calc(l, r==n?1:r+1, !c) + (c==0?0:arr[r]);
    else return mp[tmp] = calc(l==1?n:l-1, r, !c) + (c==0?0:arr[l]);
}

int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
    for(int i=1; i<=n; i++){
        sum = arr[i];
        int l = i-1, r = i+1;
        if(l<1) l+=n; if(r>n) r-=n;
        sum += calc(l, r, 0);
        printf("%lld\n", sum);
    }
}

Compilation message

cake.cpp: In function 'int main()':
cake.cpp:32:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   32 |         if(l<1) l+=n; if(r>n) r-=n;
      |         ^~
cake.cpp:32:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   32 |         if(l<1) l+=n; if(r>n) r-=n;
      |                       ^~
cake.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
cake.cpp:28:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   28 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 5540 KB Output is correct
2 Runtime error 967 ms 262148 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1353 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -