답안 #968164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968164 2024-04-23T08:10:32 Z weakweakweak Real Mountains (CCO23_day1problem2) C++17
0 / 25
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;


#define fs first
#define sc second

int n, a[20100], o[5100];


int main () {
    ios_base::sync_with_stdio(false); cin.tie(0);
    set<pii>st;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> o[i];
        st.insert({o[i], i});
    }

    long long ans = 0;
    int target = min(o[1], o[n]);
    while (st.begin()->fs != st.rbegin()->fs) {
        pii p = *st.begin(); st.erase(p);
        int i = p.sc;
        if (o[i] >= target) break;
        int left = INT_MAX, right = INT_MAX;
        for (int j = i - 1; j >= 1; j--) if (o[i] != o[j]) left = min(left, o[j]);
        for (int j = i + 1; j <= n; j++) if (o[i] != o[j]) right = min(right, o[j]);
        ans += o[i] * 1LL * left * right;
        st.insert({++o[i], i});
    }

    cout << ans % (1000000 + 3) << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -