Submission #792434

# Submission time Handle Problem Language Result Execution time Memory
792434 2023-07-25T04:48:27 Z 반딧불(#10051) Real Mountains (CCO23_day1problem2) C++17
16 / 25
5000 ms 43672 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1000003;

void input();
void makeGoal();
void solve();

int main(){
    input();
    makeGoal();
    solve();
}

int n;
ll arr[1000002];
ll goal[1000002];

void input(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
}

int L;
int numbers[1000002];
ll prfMax[1000002], sufMax[1000002];
void makeGoal(){
    for(int i=1; i<=n; i++) prfMax[i] = max(prfMax[i-1], arr[i]);
    for(int i=n; i>=1; i--) sufMax[i] = max(sufMax[i+1], arr[i]);
    for(int i=1; i<=n; i++){
        goal[i] = arr[i];
        if(prfMax[i-1] > arr[i] && sufMax[i+1] > arr[i]) goal[i] = min(prfMax[i-1], sufMax[i+1]);
    }

    for(int i=1; i<=n; i++) numbers[i] = arr[i];
    sort(numbers+1, numbers+n+1);
    L = unique(numbers+1, numbers+n+1) - numbers - 1;
}

ll sum1(ll s){
    return s*(s+1)/2%MOD;
}

ll sum1(ll s, ll e){
    return (sum1(e) - sum1(s-1) + MOD) % MOD;
}

ll ans;
void solve(){
    for(int a=1; a<L; a++){
        ll s = numbers[a], e = numbers[a+1]; /// �������� ������
        vector<int> target;
        for(int i=1; i<=n; i++){
            if(arr[i] <= s && goal[i] >= e) target.push_back(i);
        }
        if(target.empty()) continue;
        int l = target[0], r = target.back(), k = (int)target.size();
        ll lv = INF, rv = INF, mv = INF;
        for(int i=1; i<l; i++) if(arr[i] >= e) lv = min(lv, arr[i]);
        for(int i=r+1; i<=n; i++) if(arr[i] >= e) rv = min(rv, arr[i]);
        for(int i=l; i<=r; i++) if(arr[i] >= e) mv = min(mv, arr[i]);

        if(l==r){ /// �ٲ� �� �ϳ��� ���
            ans += (e-s) * (lv + rv) + sum1(s, e-1);
            ans %= MOD;
        }
        else{ /// �ٲ� �� ���� ���� ���
            if(lv > rv) swap(lv, rv);
            ans += (lv + rv + min({lv, rv, mv})) * (e-s);
            ans += sum1(s, e-1) + (e-s);
            ans += sum1(s+1, e) * 2 * (k-2);
            ans += sum1(s, e-1) * k;
            ans %= MOD;
        }

        for(int x: target) arr[x] = e;
    }
    printf("%lld", ans);
}

Compilation message

Main.cpp: In function 'void input()':
Main.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
Main.cpp:25:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     for(int i=1; i<=n; i++) scanf("%lld", &arr[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 448 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 540 KB Output is correct
17 Correct 5 ms 564 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 544 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 448 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 540 KB Output is correct
17 Correct 5 ms 564 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 544 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 139 ms 520 KB Output is correct
36 Correct 138 ms 524 KB Output is correct
37 Correct 135 ms 540 KB Output is correct
38 Correct 141 ms 544 KB Output is correct
39 Correct 142 ms 544 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 92 ms 544 KB Output is correct
44 Correct 104 ms 548 KB Output is correct
45 Correct 92 ms 520 KB Output is correct
46 Correct 96 ms 524 KB Output is correct
47 Correct 98 ms 548 KB Output is correct
48 Correct 96 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 448 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 540 KB Output is correct
17 Correct 5 ms 564 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 544 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 139 ms 520 KB Output is correct
36 Correct 138 ms 524 KB Output is correct
37 Correct 135 ms 540 KB Output is correct
38 Correct 141 ms 544 KB Output is correct
39 Correct 142 ms 544 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 92 ms 544 KB Output is correct
44 Correct 104 ms 548 KB Output is correct
45 Correct 92 ms 520 KB Output is correct
46 Correct 96 ms 524 KB Output is correct
47 Correct 98 ms 548 KB Output is correct
48 Correct 96 ms 524 KB Output is correct
49 Correct 147 ms 544 KB Output is correct
50 Correct 144 ms 640 KB Output is correct
51 Correct 142 ms 516 KB Output is correct
52 Correct 146 ms 548 KB Output is correct
53 Correct 137 ms 548 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 93 ms 520 KB Output is correct
58 Correct 92 ms 516 KB Output is correct
59 Correct 96 ms 544 KB Output is correct
60 Correct 97 ms 520 KB Output is correct
61 Correct 99 ms 524 KB Output is correct
62 Correct 108 ms 548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 448 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 540 KB Output is correct
17 Correct 5 ms 564 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 544 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1065 ms 43460 KB Output is correct
36 Correct 1097 ms 43556 KB Output is correct
37 Correct 1075 ms 43444 KB Output is correct
38 Correct 1026 ms 43476 KB Output is correct
39 Correct 1073 ms 43456 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 197 ms 43532 KB Output is correct
43 Correct 204 ms 43532 KB Output is correct
44 Correct 199 ms 43672 KB Output is correct
45 Correct 638 ms 43552 KB Output is correct
46 Correct 670 ms 43424 KB Output is correct
47 Correct 636 ms 43552 KB Output is correct
48 Correct 778 ms 43496 KB Output is correct
49 Correct 754 ms 43496 KB Output is correct
50 Correct 729 ms 43540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 448 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 540 KB Output is correct
17 Correct 5 ms 564 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 544 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 139 ms 520 KB Output is correct
36 Correct 138 ms 524 KB Output is correct
37 Correct 135 ms 540 KB Output is correct
38 Correct 141 ms 544 KB Output is correct
39 Correct 142 ms 544 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 92 ms 544 KB Output is correct
44 Correct 104 ms 548 KB Output is correct
45 Correct 92 ms 520 KB Output is correct
46 Correct 96 ms 524 KB Output is correct
47 Correct 98 ms 548 KB Output is correct
48 Correct 96 ms 524 KB Output is correct
49 Correct 1065 ms 43460 KB Output is correct
50 Correct 1097 ms 43556 KB Output is correct
51 Correct 1075 ms 43444 KB Output is correct
52 Correct 1026 ms 43476 KB Output is correct
53 Correct 1073 ms 43456 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 197 ms 43532 KB Output is correct
57 Correct 204 ms 43532 KB Output is correct
58 Correct 199 ms 43672 KB Output is correct
59 Correct 638 ms 43552 KB Output is correct
60 Correct 670 ms 43424 KB Output is correct
61 Correct 636 ms 43552 KB Output is correct
62 Correct 778 ms 43496 KB Output is correct
63 Correct 754 ms 43496 KB Output is correct
64 Correct 729 ms 43540 KB Output is correct
65 Execution timed out 5068 ms 35512 KB Time limit exceeded
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 4 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 5 ms 448 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 540 KB Output is correct
17 Correct 5 ms 564 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 4 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 544 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 468 KB Output is correct
24 Correct 3 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 139 ms 520 KB Output is correct
36 Correct 138 ms 524 KB Output is correct
37 Correct 135 ms 540 KB Output is correct
38 Correct 141 ms 544 KB Output is correct
39 Correct 142 ms 544 KB Output is correct
40 Correct 1 ms 468 KB Output is correct
41 Correct 1 ms 468 KB Output is correct
42 Correct 1 ms 468 KB Output is correct
43 Correct 92 ms 544 KB Output is correct
44 Correct 104 ms 548 KB Output is correct
45 Correct 92 ms 520 KB Output is correct
46 Correct 96 ms 524 KB Output is correct
47 Correct 98 ms 548 KB Output is correct
48 Correct 96 ms 524 KB Output is correct
49 Correct 147 ms 544 KB Output is correct
50 Correct 144 ms 640 KB Output is correct
51 Correct 142 ms 516 KB Output is correct
52 Correct 146 ms 548 KB Output is correct
53 Correct 137 ms 548 KB Output is correct
54 Correct 2 ms 468 KB Output is correct
55 Correct 1 ms 468 KB Output is correct
56 Correct 1 ms 468 KB Output is correct
57 Correct 93 ms 520 KB Output is correct
58 Correct 92 ms 516 KB Output is correct
59 Correct 96 ms 544 KB Output is correct
60 Correct 97 ms 520 KB Output is correct
61 Correct 99 ms 524 KB Output is correct
62 Correct 108 ms 548 KB Output is correct
63 Correct 1065 ms 43460 KB Output is correct
64 Correct 1097 ms 43556 KB Output is correct
65 Correct 1075 ms 43444 KB Output is correct
66 Correct 1026 ms 43476 KB Output is correct
67 Correct 1073 ms 43456 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 197 ms 43532 KB Output is correct
71 Correct 204 ms 43532 KB Output is correct
72 Correct 199 ms 43672 KB Output is correct
73 Correct 638 ms 43552 KB Output is correct
74 Correct 670 ms 43424 KB Output is correct
75 Correct 636 ms 43552 KB Output is correct
76 Correct 778 ms 43496 KB Output is correct
77 Correct 754 ms 43496 KB Output is correct
78 Correct 729 ms 43540 KB Output is correct
79 Execution timed out 5068 ms 35512 KB Time limit exceeded
80 Halted 0 ms 0 KB -