Submission #792425

# Submission time Handle Problem Language Result Execution time Memory
792425 2023-07-25T04:42:37 Z 반딧불(#10051) Real Mountains (CCO23_day1problem2) C++17
16 / 25
5000 ms 43696 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 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){ /// �ٲ� �� �ϳ��� ���
            for(ll v=s; v<e; v++){
                ans += lv + rv + v;
                ans %= MOD;
            }
        }
        else{ /// �ٲ� �� ���� ���� ���
            if(lv > rv) swap(lv, rv);
            for(ll v=s; v<e; v++){
                ans += lv + rv + (v+1) + min(lv, mv) + (v+1)*2*(k-2) + v*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 228 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 476 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 3 ms 468 KB Output is correct
12 Correct 3 ms 512 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 228 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 476 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 3 ms 468 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 500 KB Output is correct
18 Correct 5 ms 572 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 500 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 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 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 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 228 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 476 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 3 ms 468 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 500 KB Output is correct
18 Correct 5 ms 572 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 500 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 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 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 146 ms 544 KB Output is correct
36 Correct 145 ms 524 KB Output is correct
37 Correct 146 ms 648 KB Output is correct
38 Correct 145 ms 520 KB Output is correct
39 Correct 145 ms 468 KB Output is correct
40 Correct 6 ms 568 KB Output is correct
41 Correct 5 ms 572 KB Output is correct
42 Correct 5 ms 468 KB Output is correct
43 Correct 101 ms 516 KB Output is correct
44 Correct 100 ms 528 KB Output is correct
45 Correct 101 ms 504 KB Output is correct
46 Correct 118 ms 516 KB Output is correct
47 Correct 106 ms 516 KB Output is correct
48 Correct 106 ms 544 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 228 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 476 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 3 ms 468 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 500 KB Output is correct
18 Correct 5 ms 572 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 500 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 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 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 146 ms 544 KB Output is correct
36 Correct 145 ms 524 KB Output is correct
37 Correct 146 ms 648 KB Output is correct
38 Correct 145 ms 520 KB Output is correct
39 Correct 145 ms 468 KB Output is correct
40 Correct 6 ms 568 KB Output is correct
41 Correct 5 ms 572 KB Output is correct
42 Correct 5 ms 468 KB Output is correct
43 Correct 101 ms 516 KB Output is correct
44 Correct 100 ms 528 KB Output is correct
45 Correct 101 ms 504 KB Output is correct
46 Correct 118 ms 516 KB Output is correct
47 Correct 106 ms 516 KB Output is correct
48 Correct 106 ms 544 KB Output is correct
49 Correct 4117 ms 520 KB Output is correct
50 Correct 4116 ms 632 KB Output is correct
51 Correct 4120 ms 548 KB Output is correct
52 Correct 4126 ms 552 KB Output is correct
53 Correct 4118 ms 496 KB Output is correct
54 Correct 3974 ms 552 KB Output is correct
55 Correct 3985 ms 560 KB Output is correct
56 Correct 3979 ms 552 KB Output is correct
57 Correct 4066 ms 520 KB Output is correct
58 Correct 4067 ms 500 KB Output is correct
59 Correct 4125 ms 544 KB Output is correct
60 Correct 4057 ms 504 KB Output is correct
61 Correct 4049 ms 528 KB Output is correct
62 Correct 4078 ms 616 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 228 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 476 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 3 ms 468 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 500 KB Output is correct
18 Correct 5 ms 572 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 500 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 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 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 1056 ms 43620 KB Output is correct
36 Correct 1081 ms 43460 KB Output is correct
37 Correct 1043 ms 43516 KB Output is correct
38 Correct 1074 ms 43604 KB Output is correct
39 Correct 1043 ms 43580 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 198 ms 43536 KB Output is correct
43 Correct 197 ms 43524 KB Output is correct
44 Correct 199 ms 43572 KB Output is correct
45 Correct 653 ms 43472 KB Output is correct
46 Correct 660 ms 43696 KB Output is correct
47 Correct 658 ms 43520 KB Output is correct
48 Correct 807 ms 43528 KB Output is correct
49 Correct 759 ms 43564 KB Output is correct
50 Correct 761 ms 43496 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 228 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 476 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 3 ms 468 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 500 KB Output is correct
18 Correct 5 ms 572 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 500 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 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 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 146 ms 544 KB Output is correct
36 Correct 145 ms 524 KB Output is correct
37 Correct 146 ms 648 KB Output is correct
38 Correct 145 ms 520 KB Output is correct
39 Correct 145 ms 468 KB Output is correct
40 Correct 6 ms 568 KB Output is correct
41 Correct 5 ms 572 KB Output is correct
42 Correct 5 ms 468 KB Output is correct
43 Correct 101 ms 516 KB Output is correct
44 Correct 100 ms 528 KB Output is correct
45 Correct 101 ms 504 KB Output is correct
46 Correct 118 ms 516 KB Output is correct
47 Correct 106 ms 516 KB Output is correct
48 Correct 106 ms 544 KB Output is correct
49 Correct 1056 ms 43620 KB Output is correct
50 Correct 1081 ms 43460 KB Output is correct
51 Correct 1043 ms 43516 KB Output is correct
52 Correct 1074 ms 43604 KB Output is correct
53 Correct 1043 ms 43580 KB Output is correct
54 Correct 1 ms 340 KB Output is correct
55 Correct 1 ms 340 KB Output is correct
56 Correct 198 ms 43536 KB Output is correct
57 Correct 197 ms 43524 KB Output is correct
58 Correct 199 ms 43572 KB Output is correct
59 Correct 653 ms 43472 KB Output is correct
60 Correct 660 ms 43696 KB Output is correct
61 Correct 658 ms 43520 KB Output is correct
62 Correct 807 ms 43528 KB Output is correct
63 Correct 759 ms 43564 KB Output is correct
64 Correct 761 ms 43496 KB Output is correct
65 Execution timed out 5059 ms 35648 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 228 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 476 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 3 ms 468 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 468 KB Output is correct
17 Correct 5 ms 500 KB Output is correct
18 Correct 5 ms 572 KB Output is correct
19 Correct 5 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 2 ms 500 KB Output is correct
23 Correct 4 ms 468 KB Output is correct
24 Correct 4 ms 468 KB Output is correct
25 Correct 3 ms 468 KB Output is correct
26 Correct 4 ms 468 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 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 340 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 146 ms 544 KB Output is correct
36 Correct 145 ms 524 KB Output is correct
37 Correct 146 ms 648 KB Output is correct
38 Correct 145 ms 520 KB Output is correct
39 Correct 145 ms 468 KB Output is correct
40 Correct 6 ms 568 KB Output is correct
41 Correct 5 ms 572 KB Output is correct
42 Correct 5 ms 468 KB Output is correct
43 Correct 101 ms 516 KB Output is correct
44 Correct 100 ms 528 KB Output is correct
45 Correct 101 ms 504 KB Output is correct
46 Correct 118 ms 516 KB Output is correct
47 Correct 106 ms 516 KB Output is correct
48 Correct 106 ms 544 KB Output is correct
49 Correct 4117 ms 520 KB Output is correct
50 Correct 4116 ms 632 KB Output is correct
51 Correct 4120 ms 548 KB Output is correct
52 Correct 4126 ms 552 KB Output is correct
53 Correct 4118 ms 496 KB Output is correct
54 Correct 3974 ms 552 KB Output is correct
55 Correct 3985 ms 560 KB Output is correct
56 Correct 3979 ms 552 KB Output is correct
57 Correct 4066 ms 520 KB Output is correct
58 Correct 4067 ms 500 KB Output is correct
59 Correct 4125 ms 544 KB Output is correct
60 Correct 4057 ms 504 KB Output is correct
61 Correct 4049 ms 528 KB Output is correct
62 Correct 4078 ms 616 KB Output is correct
63 Correct 1056 ms 43620 KB Output is correct
64 Correct 1081 ms 43460 KB Output is correct
65 Correct 1043 ms 43516 KB Output is correct
66 Correct 1074 ms 43604 KB Output is correct
67 Correct 1043 ms 43580 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 198 ms 43536 KB Output is correct
71 Correct 197 ms 43524 KB Output is correct
72 Correct 199 ms 43572 KB Output is correct
73 Correct 653 ms 43472 KB Output is correct
74 Correct 660 ms 43696 KB Output is correct
75 Correct 658 ms 43520 KB Output is correct
76 Correct 807 ms 43528 KB Output is correct
77 Correct 759 ms 43564 KB Output is correct
78 Correct 761 ms 43496 KB Output is correct
79 Execution timed out 5059 ms 35648 KB Time limit exceeded
80 Halted 0 ms 0 KB -