답안 #747321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747321 2023-05-24T05:24:52 Z Paul_Liao_1457 Reconstruction Project (JOI22_reconstruction) C++17
100 / 100
4021 ms 59360 KB
#define LOCAL
#include<iostream>
#include<array>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
#include<unordered_map>
#include<cstring>
#include<iomanip>
#include<bitset>
#include<tuple>

#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=b;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int boss[505];

int find(int x) {
    if (boss[x] == x) return x;
    return boss[x] = find(boss[x]);
}

void merge(int a, int b) {
    if(a == b) return;
    boss[a] = b;
}

signed main() {

    AC;

    int n, m;
    cin >> n >> m;

    vector<pair<int, pair<int, int>>> v;

    FOR(i, 0, m) {
        int a, b, w;
        cin >> a >> b >> w;
        v.pb(mp(w, mp(a, b)));
    }

    int q;
    cin >> q;

    vector<pair<pair<int,  bool>, pair<int, int>>> op;
    
    FOR(i, 0, q) {
        int x; cin >> x;
        op.pb(mp(mp(x, 0), mp(0,0)));
    }
    
    //cout << "hi1" << endl;

    sort(v.begin(), v.end());

    multiset<int> cur;

    FOR(i, 0, m) {
        FOR(i, 1, n+1) boss[i] = i;

        int now = i - 1;
        while (now >= 0) {
            merge(find(v[now].S.F), find(v[now].S.S));
            if(find(v[i].S.F) == find(v[i].S.S)) break;
            now--;
        }

        if (now < 0) {
            cur.insert(v[i].F);        
        } else {
            op.pb(mp(mp((v[i].F + v[now].F)/2, 1), mp(v[now].F, v[i].F)));
        }
    }

    sort(op.begin(), op.end());

    vector<ll> ans;

    FOR(i, 0, op.size()) {
         if (!op[i].F.S) {
            ll sum = 0;
            for (auto j:cur) sum += abs(j - op[i].F.F);
            ans.pb(sum);
         } else {
            cur.erase(cur.find(op[i].S.F));
            cur.insert(op[i].S.S);
         }
    }

    //cout << "hi" << endl;
    
    
    FOR(i, 0, ans.size()) cout << ans[i] << endl;
}

Compilation message

reconstruction.cpp: In function 'int main()':
reconstruction.cpp:19:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, bool>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 | #define FOR(i,a,b) for(int i=a;i<b;i++)
......
   94 |     FOR(i, 0, op.size()) {
      |         ~~~~~~~~~~~~~~~          
reconstruction.cpp:94:5: note: in expansion of macro 'FOR'
   94 |     FOR(i, 0, op.size()) {
      |     ^~~
reconstruction.cpp:19:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 | #define FOR(i,a,b) for(int i=a;i<b;i++)
......
  108 |     FOR(i, 0, ans.size()) cout << ans[i] << endl;
      |         ~~~~~~~~~~~~~~~~         
reconstruction.cpp:108:5: note: in expansion of macro 'FOR'
  108 |     FOR(i, 0, ans.size()) cout << ans[i] << endl;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 1123 ms 6196 KB Output is correct
21 Correct 632 ms 6204 KB Output is correct
22 Correct 689 ms 6264 KB Output is correct
23 Correct 764 ms 6244 KB Output is correct
24 Correct 964 ms 6188 KB Output is correct
25 Correct 1163 ms 6260 KB Output is correct
26 Correct 1087 ms 6288 KB Output is correct
27 Correct 1115 ms 6416 KB Output is correct
28 Correct 1102 ms 6216 KB Output is correct
29 Correct 857 ms 6276 KB Output is correct
30 Correct 1104 ms 6364 KB Output is correct
31 Correct 1089 ms 6196 KB Output is correct
32 Correct 1071 ms 6212 KB Output is correct
33 Correct 1097 ms 6332 KB Output is correct
34 Correct 540 ms 6372 KB Output is correct
35 Correct 1119 ms 6236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 3411 ms 57208 KB Output is correct
5 Correct 3377 ms 57160 KB Output is correct
6 Correct 3361 ms 57204 KB Output is correct
7 Correct 3048 ms 59236 KB Output is correct
8 Correct 2682 ms 59128 KB Output is correct
9 Correct 2521 ms 59148 KB Output is correct
10 Correct 3318 ms 57240 KB Output is correct
11 Correct 2610 ms 59360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 2641 ms 54136 KB Output is correct
21 Correct 2618 ms 54176 KB Output is correct
22 Correct 2637 ms 54044 KB Output is correct
23 Correct 2621 ms 53948 KB Output is correct
24 Correct 2632 ms 54128 KB Output is correct
25 Correct 2592 ms 53892 KB Output is correct
26 Correct 2627 ms 54052 KB Output is correct
27 Correct 2439 ms 54056 KB Output is correct
28 Correct 2605 ms 53968 KB Output is correct
29 Correct 2590 ms 53948 KB Output is correct
30 Correct 2758 ms 54112 KB Output is correct
31 Correct 2459 ms 53848 KB Output is correct
32 Correct 2253 ms 54696 KB Output is correct
33 Correct 2627 ms 53976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 1123 ms 6196 KB Output is correct
21 Correct 632 ms 6204 KB Output is correct
22 Correct 689 ms 6264 KB Output is correct
23 Correct 764 ms 6244 KB Output is correct
24 Correct 964 ms 6188 KB Output is correct
25 Correct 1163 ms 6260 KB Output is correct
26 Correct 1087 ms 6288 KB Output is correct
27 Correct 1115 ms 6416 KB Output is correct
28 Correct 1102 ms 6216 KB Output is correct
29 Correct 857 ms 6276 KB Output is correct
30 Correct 1104 ms 6364 KB Output is correct
31 Correct 1089 ms 6196 KB Output is correct
32 Correct 1071 ms 6212 KB Output is correct
33 Correct 1097 ms 6332 KB Output is correct
34 Correct 540 ms 6372 KB Output is correct
35 Correct 1119 ms 6236 KB Output is correct
36 Correct 1196 ms 6656 KB Output is correct
37 Correct 702 ms 6628 KB Output is correct
38 Correct 764 ms 6392 KB Output is correct
39 Correct 841 ms 6536 KB Output is correct
40 Correct 1018 ms 6584 KB Output is correct
41 Correct 1222 ms 6464 KB Output is correct
42 Correct 1179 ms 6444 KB Output is correct
43 Correct 1167 ms 6736 KB Output is correct
44 Correct 1140 ms 6692 KB Output is correct
45 Correct 882 ms 6484 KB Output is correct
46 Correct 1169 ms 6560 KB Output is correct
47 Correct 1163 ms 6476 KB Output is correct
48 Correct 1158 ms 6420 KB Output is correct
49 Correct 1163 ms 6680 KB Output is correct
50 Correct 591 ms 6544 KB Output is correct
51 Correct 1145 ms 6420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 320 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 436 KB Output is correct
20 Correct 1123 ms 6196 KB Output is correct
21 Correct 632 ms 6204 KB Output is correct
22 Correct 689 ms 6264 KB Output is correct
23 Correct 764 ms 6244 KB Output is correct
24 Correct 964 ms 6188 KB Output is correct
25 Correct 1163 ms 6260 KB Output is correct
26 Correct 1087 ms 6288 KB Output is correct
27 Correct 1115 ms 6416 KB Output is correct
28 Correct 1102 ms 6216 KB Output is correct
29 Correct 857 ms 6276 KB Output is correct
30 Correct 1104 ms 6364 KB Output is correct
31 Correct 1089 ms 6196 KB Output is correct
32 Correct 1071 ms 6212 KB Output is correct
33 Correct 1097 ms 6332 KB Output is correct
34 Correct 540 ms 6372 KB Output is correct
35 Correct 1119 ms 6236 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 0 ms 324 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 3411 ms 57208 KB Output is correct
40 Correct 3377 ms 57160 KB Output is correct
41 Correct 3361 ms 57204 KB Output is correct
42 Correct 3048 ms 59236 KB Output is correct
43 Correct 2682 ms 59128 KB Output is correct
44 Correct 2521 ms 59148 KB Output is correct
45 Correct 3318 ms 57240 KB Output is correct
46 Correct 2610 ms 59360 KB Output is correct
47 Correct 1 ms 212 KB Output is correct
48 Correct 2641 ms 54136 KB Output is correct
49 Correct 2618 ms 54176 KB Output is correct
50 Correct 2637 ms 54044 KB Output is correct
51 Correct 2621 ms 53948 KB Output is correct
52 Correct 2632 ms 54128 KB Output is correct
53 Correct 2592 ms 53892 KB Output is correct
54 Correct 2627 ms 54052 KB Output is correct
55 Correct 2439 ms 54056 KB Output is correct
56 Correct 2605 ms 53968 KB Output is correct
57 Correct 2590 ms 53948 KB Output is correct
58 Correct 2758 ms 54112 KB Output is correct
59 Correct 2459 ms 53848 KB Output is correct
60 Correct 2253 ms 54696 KB Output is correct
61 Correct 2627 ms 53976 KB Output is correct
62 Correct 1196 ms 6656 KB Output is correct
63 Correct 702 ms 6628 KB Output is correct
64 Correct 764 ms 6392 KB Output is correct
65 Correct 841 ms 6536 KB Output is correct
66 Correct 1018 ms 6584 KB Output is correct
67 Correct 1222 ms 6464 KB Output is correct
68 Correct 1179 ms 6444 KB Output is correct
69 Correct 1167 ms 6736 KB Output is correct
70 Correct 1140 ms 6692 KB Output is correct
71 Correct 882 ms 6484 KB Output is correct
72 Correct 1169 ms 6560 KB Output is correct
73 Correct 1163 ms 6476 KB Output is correct
74 Correct 1158 ms 6420 KB Output is correct
75 Correct 1163 ms 6680 KB Output is correct
76 Correct 591 ms 6544 KB Output is correct
77 Correct 1145 ms 6420 KB Output is correct
78 Correct 3823 ms 56200 KB Output is correct
79 Correct 3358 ms 58236 KB Output is correct
80 Correct 3359 ms 57400 KB Output is correct
81 Correct 3486 ms 57308 KB Output is correct
82 Correct 3721 ms 56276 KB Output is correct
83 Correct 3970 ms 56076 KB Output is correct
84 Correct 4021 ms 56208 KB Output is correct
85 Correct 3781 ms 56156 KB Output is correct
86 Correct 3582 ms 56160 KB Output is correct
87 Correct 3147 ms 57996 KB Output is correct
88 Correct 3816 ms 56244 KB Output is correct
89 Correct 3814 ms 56188 KB Output is correct
90 Correct 3766 ms 56464 KB Output is correct
91 Correct 3772 ms 56020 KB Output is correct
92 Correct 2742 ms 59148 KB Output is correct
93 Correct 3797 ms 57340 KB Output is correct