Submission #796173

# Submission time Handle Problem Language Result Execution time Memory
796173 2023-07-28T07:21:48 Z 이동현(#10071) Security Guard (JOI23_guard) C++17
37 / 100
162 ms 18472 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 NS = (int)2e5 + 4;
int n, m, q;
int a[NS], srt[NS], chk[NS];
vector<int> way[NS];

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

    cin >> n >> m >> q;
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 1; i <= m; ++i){
        int x, y;
        cin >> x >> y;
        way[x].push_back(y);
        way[y].push_back(x);
        ans += min(a[x], a[y]);
    }

    iota(srt, srt + NS, 0);
    sort(srt + 1, srt + n + 1, [&](int x, int y){return a[x] > a[y];});

    int gr = 1;
    chk[0] = chk[n + 1] = 1;
    for(int i = 1; i <= n; ++i){
        int now = srt[i];
        
        chk[now] = 1;
        gr += (int)way[now].size() - 1;
        for(auto&nxt:way[now]){
            gr -= chk[nxt];
        }

        ans += gr * (a[srt[i]] - a[srt[i + 1]]);
    }

    assert(gr == 0);

    cout << ans << '\n';
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 58 ms 15900 KB Output is correct
3 Correct 60 ms 15928 KB Output is correct
4 Correct 63 ms 15940 KB Output is correct
5 Correct 63 ms 15908 KB Output is correct
6 Correct 63 ms 15844 KB Output is correct
7 Correct 61 ms 15852 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 58 ms 15900 KB Output is correct
3 Correct 60 ms 15928 KB Output is correct
4 Correct 63 ms 15940 KB Output is correct
5 Correct 63 ms 15908 KB Output is correct
6 Correct 63 ms 15844 KB Output is correct
7 Correct 61 ms 15852 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 90 ms 15852 KB Output is correct
11 Correct 83 ms 15904 KB Output is correct
12 Correct 69 ms 15936 KB Output is correct
13 Correct 68 ms 15932 KB Output is correct
14 Correct 89 ms 15912 KB Output is correct
15 Correct 90 ms 15964 KB Output is correct
16 Correct 101 ms 15940 KB Output is correct
17 Correct 89 ms 15948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 58 ms 15900 KB Output is correct
3 Correct 60 ms 15928 KB Output is correct
4 Correct 63 ms 15940 KB Output is correct
5 Correct 63 ms 15908 KB Output is correct
6 Correct 63 ms 15844 KB Output is correct
7 Correct 61 ms 15852 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 90 ms 15852 KB Output is correct
11 Correct 83 ms 15904 KB Output is correct
12 Correct 69 ms 15936 KB Output is correct
13 Correct 68 ms 15932 KB Output is correct
14 Correct 89 ms 15912 KB Output is correct
15 Correct 90 ms 15964 KB Output is correct
16 Correct 101 ms 15940 KB Output is correct
17 Correct 89 ms 15948 KB Output is correct
18 Correct 3 ms 6484 KB Output is correct
19 Correct 126 ms 17324 KB Output is correct
20 Correct 144 ms 17280 KB Output is correct
21 Correct 124 ms 17076 KB Output is correct
22 Correct 118 ms 17392 KB Output is correct
23 Correct 128 ms 18196 KB Output is correct
24 Correct 111 ms 18196 KB Output is correct
25 Correct 148 ms 17856 KB Output is correct
26 Correct 98 ms 17776 KB Output is correct
27 Correct 97 ms 17728 KB Output is correct
28 Correct 129 ms 16648 KB Output is correct
29 Correct 134 ms 16888 KB Output is correct
30 Correct 141 ms 17600 KB Output is correct
31 Correct 102 ms 17780 KB Output is correct
32 Correct 136 ms 17920 KB Output is correct
33 Correct 114 ms 18472 KB Output is correct
34 Correct 103 ms 17464 KB Output is correct
35 Correct 138 ms 18472 KB Output is correct
36 Correct 84 ms 18124 KB Output is correct
37 Correct 94 ms 18160 KB Output is correct
38 Correct 116 ms 17940 KB Output is correct
39 Correct 106 ms 17008 KB Output is correct
40 Correct 113 ms 17404 KB Output is correct
41 Correct 124 ms 16376 KB Output is correct
42 Correct 109 ms 15968 KB Output is correct
43 Correct 113 ms 17220 KB Output is correct
44 Correct 137 ms 17500 KB Output is correct
45 Correct 100 ms 17464 KB Output is correct
46 Correct 106 ms 17336 KB Output is correct
47 Correct 115 ms 17436 KB Output is correct
48 Correct 162 ms 17444 KB Output is correct
49 Correct 114 ms 17304 KB Output is correct
50 Correct 121 ms 17496 KB Output is correct
51 Correct 120 ms 17532 KB Output is correct
52 Correct 90 ms 17308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 58 ms 15900 KB Output is correct
3 Correct 60 ms 15928 KB Output is correct
4 Correct 63 ms 15940 KB Output is correct
5 Correct 63 ms 15908 KB Output is correct
6 Correct 63 ms 15844 KB Output is correct
7 Correct 61 ms 15852 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 90 ms 15852 KB Output is correct
11 Correct 83 ms 15904 KB Output is correct
12 Correct 69 ms 15936 KB Output is correct
13 Correct 68 ms 15932 KB Output is correct
14 Correct 89 ms 15912 KB Output is correct
15 Correct 90 ms 15964 KB Output is correct
16 Correct 101 ms 15940 KB Output is correct
17 Correct 89 ms 15948 KB Output is correct
18 Correct 3 ms 6484 KB Output is correct
19 Correct 126 ms 17324 KB Output is correct
20 Correct 144 ms 17280 KB Output is correct
21 Correct 124 ms 17076 KB Output is correct
22 Correct 118 ms 17392 KB Output is correct
23 Correct 128 ms 18196 KB Output is correct
24 Correct 111 ms 18196 KB Output is correct
25 Correct 148 ms 17856 KB Output is correct
26 Correct 98 ms 17776 KB Output is correct
27 Correct 97 ms 17728 KB Output is correct
28 Correct 129 ms 16648 KB Output is correct
29 Correct 134 ms 16888 KB Output is correct
30 Correct 141 ms 17600 KB Output is correct
31 Correct 102 ms 17780 KB Output is correct
32 Correct 136 ms 17920 KB Output is correct
33 Correct 114 ms 18472 KB Output is correct
34 Correct 103 ms 17464 KB Output is correct
35 Correct 138 ms 18472 KB Output is correct
36 Correct 84 ms 18124 KB Output is correct
37 Correct 94 ms 18160 KB Output is correct
38 Correct 116 ms 17940 KB Output is correct
39 Correct 106 ms 17008 KB Output is correct
40 Correct 113 ms 17404 KB Output is correct
41 Correct 124 ms 16376 KB Output is correct
42 Correct 109 ms 15968 KB Output is correct
43 Correct 113 ms 17220 KB Output is correct
44 Correct 137 ms 17500 KB Output is correct
45 Correct 100 ms 17464 KB Output is correct
46 Correct 106 ms 17336 KB Output is correct
47 Correct 115 ms 17436 KB Output is correct
48 Correct 162 ms 17444 KB Output is correct
49 Correct 114 ms 17304 KB Output is correct
50 Correct 121 ms 17496 KB Output is correct
51 Correct 120 ms 17532 KB Output is correct
52 Correct 90 ms 17308 KB Output is correct
53 Runtime error 8 ms 13140 KB Execution killed with signal 6
54 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Incorrect 4 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Incorrect 4 ms 6484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6484 KB Output is correct
2 Correct 58 ms 15900 KB Output is correct
3 Correct 60 ms 15928 KB Output is correct
4 Correct 63 ms 15940 KB Output is correct
5 Correct 63 ms 15908 KB Output is correct
6 Correct 63 ms 15844 KB Output is correct
7 Correct 61 ms 15852 KB Output is correct
8 Correct 3 ms 6484 KB Output is correct
9 Correct 3 ms 6484 KB Output is correct
10 Correct 90 ms 15852 KB Output is correct
11 Correct 83 ms 15904 KB Output is correct
12 Correct 69 ms 15936 KB Output is correct
13 Correct 68 ms 15932 KB Output is correct
14 Correct 89 ms 15912 KB Output is correct
15 Correct 90 ms 15964 KB Output is correct
16 Correct 101 ms 15940 KB Output is correct
17 Correct 89 ms 15948 KB Output is correct
18 Correct 3 ms 6484 KB Output is correct
19 Correct 126 ms 17324 KB Output is correct
20 Correct 144 ms 17280 KB Output is correct
21 Correct 124 ms 17076 KB Output is correct
22 Correct 118 ms 17392 KB Output is correct
23 Correct 128 ms 18196 KB Output is correct
24 Correct 111 ms 18196 KB Output is correct
25 Correct 148 ms 17856 KB Output is correct
26 Correct 98 ms 17776 KB Output is correct
27 Correct 97 ms 17728 KB Output is correct
28 Correct 129 ms 16648 KB Output is correct
29 Correct 134 ms 16888 KB Output is correct
30 Correct 141 ms 17600 KB Output is correct
31 Correct 102 ms 17780 KB Output is correct
32 Correct 136 ms 17920 KB Output is correct
33 Correct 114 ms 18472 KB Output is correct
34 Correct 103 ms 17464 KB Output is correct
35 Correct 138 ms 18472 KB Output is correct
36 Correct 84 ms 18124 KB Output is correct
37 Correct 94 ms 18160 KB Output is correct
38 Correct 116 ms 17940 KB Output is correct
39 Correct 106 ms 17008 KB Output is correct
40 Correct 113 ms 17404 KB Output is correct
41 Correct 124 ms 16376 KB Output is correct
42 Correct 109 ms 15968 KB Output is correct
43 Correct 113 ms 17220 KB Output is correct
44 Correct 137 ms 17500 KB Output is correct
45 Correct 100 ms 17464 KB Output is correct
46 Correct 106 ms 17336 KB Output is correct
47 Correct 115 ms 17436 KB Output is correct
48 Correct 162 ms 17444 KB Output is correct
49 Correct 114 ms 17304 KB Output is correct
50 Correct 121 ms 17496 KB Output is correct
51 Correct 120 ms 17532 KB Output is correct
52 Correct 90 ms 17308 KB Output is correct
53 Runtime error 8 ms 13140 KB Execution killed with signal 6
54 Halted 0 ms 0 KB -