답안 #792525

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
792525 2023-07-25T06:23:10 Z 이동현(#10054) Real Mountains (CCO23_day1problem2) C++17
6 / 25
5000 ms 31648 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define int long long
using namespace std;

const int mod = (int)1e6 + 3;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n), srt(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        srt[i] = a[i];
    }
    sort(srt.begin(), srt.end());
    srt.erase(unique(srt.begin(), srt.end()), srt.end());

    int ans = 0;
    for(int i = 0; i + 1 < (int)srt.size(); ++i){
        vector<int> lmn(n, -1), rmn(n, -1);
        set<int> st;

        for(int j = 0; j < n; ++j){
            auto p = st.lower_bound(a[j] + 1);
            if(p != st.end()){
                lmn[j] = *p;
            }
            st.insert(a[j]);
        }
        st.clear();
        for(int j = n - 1; j >= 0; --j){
            auto p = st.lower_bound(a[j] + 1);
            if(p != st.end()){
                rmn[j] = *p;
            }
            st.insert(a[j]);
        }

        int cnt = 0;
        int mn = -1, mx = n;
        for(int j = 0; j < n; ++j){
            if(lmn[j] != -1 && rmn[j] != -1 && a[j] == srt[i]){
                if(mn == -1) mn = j;
                mx = j;
                ++cnt;
                a[j] = srt[i + 1];
            }
        }
        if(cnt){
            if(cnt == 1){
                (ans += (lmn[mn] + rmn[mn]) * (srt[i + 1] - srt[i]) % mod) %= mod;
            
        assert(ans >= 0 && ans < mod);}
            else{
                (ans += (lmn[mn] + rmn[mx] + min(rmn[mn], lmn[mx])) * (srt[i + 1] - srt[i]) % mod + (srt[i] + srt[i + 1] + 1) * (srt[i + 1] - srt[i]) / 2 % mod * (cnt * 2 - 3) % mod) %= mod;
           
        assert(ans >= 0 && ans < mod); }
        assert(ans >= 0 && ans < mod);
            (ans += cnt * (srt[i] + srt[i + 1] - 1) % mod * (srt[i + 1] - srt[i]) / 2 % mod) %= mod;

            // cout << fir << ' ' << lst << ' ' << cnt << ' ' << ans << endl;
        }

        assert(ans >= 0 && ans < mod);
    }

    cout << ans << '\n';
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 18 ms 480 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 20 ms 484 KB Output is correct
10 Correct 24 ms 468 KB Output is correct
11 Correct 16 ms 476 KB Output is correct
12 Correct 23 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 18 ms 480 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 20 ms 484 KB Output is correct
10 Correct 24 ms 468 KB Output is correct
11 Correct 16 ms 476 KB Output is correct
12 Correct 23 ms 484 KB Output is correct
13 Correct 34 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 41 ms 468 KB Output is correct
17 Correct 34 ms 468 KB Output is correct
18 Correct 33 ms 468 KB Output is correct
19 Correct 40 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 17 ms 480 KB Output is correct
24 Correct 20 ms 468 KB Output is correct
25 Correct 17 ms 476 KB Output is correct
26 Correct 28 ms 476 KB Output is correct
27 Correct 27 ms 472 KB Output is correct
28 Correct 22 ms 468 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 18 ms 480 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 20 ms 484 KB Output is correct
10 Correct 24 ms 468 KB Output is correct
11 Correct 16 ms 476 KB Output is correct
12 Correct 23 ms 484 KB Output is correct
13 Correct 34 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 41 ms 468 KB Output is correct
17 Correct 34 ms 468 KB Output is correct
18 Correct 33 ms 468 KB Output is correct
19 Correct 40 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 17 ms 480 KB Output is correct
24 Correct 20 ms 468 KB Output is correct
25 Correct 17 ms 476 KB Output is correct
26 Correct 28 ms 476 KB Output is correct
27 Correct 27 ms 472 KB Output is correct
28 Correct 22 ms 468 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Incorrect 4554 ms 688 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 18 ms 480 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 20 ms 484 KB Output is correct
10 Correct 24 ms 468 KB Output is correct
11 Correct 16 ms 476 KB Output is correct
12 Correct 23 ms 484 KB Output is correct
13 Correct 34 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 41 ms 468 KB Output is correct
17 Correct 34 ms 468 KB Output is correct
18 Correct 33 ms 468 KB Output is correct
19 Correct 40 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 17 ms 480 KB Output is correct
24 Correct 20 ms 468 KB Output is correct
25 Correct 17 ms 476 KB Output is correct
26 Correct 28 ms 476 KB Output is correct
27 Correct 27 ms 472 KB Output is correct
28 Correct 22 ms 468 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Incorrect 4554 ms 688 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 18 ms 480 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 20 ms 484 KB Output is correct
10 Correct 24 ms 468 KB Output is correct
11 Correct 16 ms 476 KB Output is correct
12 Correct 23 ms 484 KB Output is correct
13 Correct 34 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 41 ms 468 KB Output is correct
17 Correct 34 ms 468 KB Output is correct
18 Correct 33 ms 468 KB Output is correct
19 Correct 40 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 17 ms 480 KB Output is correct
24 Correct 20 ms 468 KB Output is correct
25 Correct 17 ms 476 KB Output is correct
26 Correct 28 ms 476 KB Output is correct
27 Correct 27 ms 472 KB Output is correct
28 Correct 22 ms 468 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Execution timed out 5102 ms 31648 KB Time limit exceeded
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 18 ms 480 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 20 ms 484 KB Output is correct
10 Correct 24 ms 468 KB Output is correct
11 Correct 16 ms 476 KB Output is correct
12 Correct 23 ms 484 KB Output is correct
13 Correct 34 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 41 ms 468 KB Output is correct
17 Correct 34 ms 468 KB Output is correct
18 Correct 33 ms 468 KB Output is correct
19 Correct 40 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 17 ms 480 KB Output is correct
24 Correct 20 ms 468 KB Output is correct
25 Correct 17 ms 476 KB Output is correct
26 Correct 28 ms 476 KB Output is correct
27 Correct 27 ms 472 KB Output is correct
28 Correct 22 ms 468 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Incorrect 4554 ms 688 KB Output isn't correct
36 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 18 ms 480 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 404 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 20 ms 484 KB Output is correct
10 Correct 24 ms 468 KB Output is correct
11 Correct 16 ms 476 KB Output is correct
12 Correct 23 ms 484 KB Output is correct
13 Correct 34 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 41 ms 468 KB Output is correct
17 Correct 34 ms 468 KB Output is correct
18 Correct 33 ms 468 KB Output is correct
19 Correct 40 ms 468 KB Output is correct
20 Correct 4 ms 480 KB Output is correct
21 Correct 3 ms 468 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 17 ms 480 KB Output is correct
24 Correct 20 ms 468 KB Output is correct
25 Correct 17 ms 476 KB Output is correct
26 Correct 28 ms 476 KB Output is correct
27 Correct 27 ms 472 KB Output is correct
28 Correct 22 ms 468 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Incorrect 4554 ms 688 KB Output isn't correct
36 Halted 0 ms 0 KB -