답안 #792481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792481 2023-07-25T05:29:33 Z 이성호(#10053) Real Mountains (CCO23_day1problem2) C++17
0 / 25
1 ms 340 KB
#include <iostream>
#define int long long
using namespace std;

int calc(int H1, int H2, int h, int k)
{
    if (H1 < H2) swap(H1, H2);
    if (k == 1) return (H1 + H2) * (H2 - h) + (H2 - 1 + h) * (H2 - h) / 2;
    else return (H2 + h - 1) * (H2 - h) * (3 * k - 3) / 2 + (H2 - h) * (H1 + 2 * H2 + 2 * k - 3);
}

int N;
int h[5005];

signed main()
{
    cin >> N;
    int m = 10000000, l = -1, r = -1;
    for (int i = 1; i <= N; i++) {
        cin >> h[i];
        if (m > h[i]) {
            l = r = i;
            m = h[i];
        }
        else if (m == h[i]) r = i;
    }
    int ans = 0, cur = m;
    while (1) {
        if (l == 1 || r == N) break;
        ans += calc(h[l-1], h[r+1], cur, r - l + 1);
        if (h[l-1] >= h[r+1]) cur = h[++r];
        else cur = h[--l];
    }
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -