답안 #1098986

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1098986 2024-10-10T11:54:06 Z razivo Stranded Far From Home (BOI22_island) C++14
100 / 100
245 ms 42428 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long find(long long p, vector<long long> &dsu) {
    if(p==dsu[p]) return p;
    long long u = find(dsu[p],dsu);
    dsu[p]=u;
    return u;
}
void un(long long a,long long b,vector<long long> &dsu,vector<long long> &ev,vector<long long> &maxv,vector<vector<long long>> &group) {
    a=find(a,dsu);
    b=find(b,dsu);
    if(a==b) return;
    if(maxv[a]>ev[b]) group[b].clear();
    if(maxv[b]>ev[a]) group[a].clear();
    if(group[a].size()>group[b].size()) swap(a,b);
    for(int i : group[a]) group[b].push_back(i);
    dsu[a]=b;
    maxv[b]=max(maxv[b],maxv[a]);
    ev[b]+=ev[a];
}
int main()
{
    long long n,m;
    cin>>n>>m;
    vector<long long> v(n),ev(n),dsu(n),maxv(n);
    vector<vector<long long>> group(n);
    vector<pair<long long,long long>> s;
    for (long long i = 0; i < n; ++i) {
        long long x; cin>>x;
        ev[i]=x;
        maxv[i]=x;
        group[i].push_back(i);
        v[i]=x;
        s.push_back({x,i});
        dsu[i]=i;
    }
    sort(s.begin(), s.end());
    vector<pair<pair<long long,long long>,pair<long long,long long>>> ed;
    for (long long i = 0; i < m; ++i) {
        long long x,y; cin>>x>>y; x--; y--;
        if(v[x]<v[y]) swap(x,y);
        ed.push_back({{v[x],v[y]},{x,y}});
    }
    sort(ed.begin(),ed.end());
    for (auto [u,t]:ed) {
        auto [a,b] = t;
        if(ev[find(a,dsu)]>=v[b]) un(a,b,dsu,ev,maxv,group);
    }
    long long ma = find(s[n-1].second,dsu);
    vector<bool> ans(n,false);
    for (long long i :group[ma]) {
        ans[i]=true;
    }
    for (int i = 0; i < n; ++i) {
        if(ans[i]) cout<<"1";
        else cout<<"0";
    }
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:47:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   47 |     for (auto [u,t]:ed) {
      |               ^
island.cpp:48:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |         auto [a,b] = t;
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 704 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 184 ms 34588 KB Output is correct
4 Correct 146 ms 33624 KB Output is correct
5 Correct 184 ms 36912 KB Output is correct
6 Correct 202 ms 38412 KB Output is correct
7 Correct 184 ms 38184 KB Output is correct
8 Correct 193 ms 35120 KB Output is correct
9 Correct 174 ms 42388 KB Output is correct
10 Correct 153 ms 32076 KB Output is correct
11 Correct 171 ms 34088 KB Output is correct
12 Correct 172 ms 32636 KB Output is correct
13 Correct 191 ms 33576 KB Output is correct
14 Correct 149 ms 33576 KB Output is correct
15 Correct 174 ms 35112 KB Output is correct
16 Correct 130 ms 34096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 198 ms 39540 KB Output is correct
3 Correct 201 ms 39980 KB Output is correct
4 Correct 180 ms 35112 KB Output is correct
5 Correct 134 ms 33068 KB Output is correct
6 Correct 209 ms 39720 KB Output is correct
7 Correct 193 ms 35112 KB Output is correct
8 Correct 197 ms 35140 KB Output is correct
9 Correct 140 ms 34184 KB Output is correct
10 Correct 156 ms 32840 KB Output is correct
11 Correct 170 ms 35112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 210 ms 35300 KB Output is correct
3 Correct 217 ms 36392 KB Output is correct
4 Correct 219 ms 38052 KB Output is correct
5 Correct 225 ms 41008 KB Output is correct
6 Correct 199 ms 36656 KB Output is correct
7 Correct 180 ms 35112 KB Output is correct
8 Correct 141 ms 33072 KB Output is correct
9 Correct 136 ms 21044 KB Output is correct
10 Correct 176 ms 41064 KB Output is correct
11 Correct 173 ms 35108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 704 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 544 KB Output is correct
9 Correct 2 ms 692 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 184 ms 34588 KB Output is correct
18 Correct 146 ms 33624 KB Output is correct
19 Correct 184 ms 36912 KB Output is correct
20 Correct 202 ms 38412 KB Output is correct
21 Correct 184 ms 38184 KB Output is correct
22 Correct 193 ms 35120 KB Output is correct
23 Correct 174 ms 42388 KB Output is correct
24 Correct 153 ms 32076 KB Output is correct
25 Correct 171 ms 34088 KB Output is correct
26 Correct 172 ms 32636 KB Output is correct
27 Correct 191 ms 33576 KB Output is correct
28 Correct 149 ms 33576 KB Output is correct
29 Correct 174 ms 35112 KB Output is correct
30 Correct 130 ms 34096 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 198 ms 39540 KB Output is correct
33 Correct 201 ms 39980 KB Output is correct
34 Correct 180 ms 35112 KB Output is correct
35 Correct 134 ms 33068 KB Output is correct
36 Correct 209 ms 39720 KB Output is correct
37 Correct 193 ms 35112 KB Output is correct
38 Correct 197 ms 35140 KB Output is correct
39 Correct 140 ms 34184 KB Output is correct
40 Correct 156 ms 32840 KB Output is correct
41 Correct 170 ms 35112 KB Output is correct
42 Correct 0 ms 348 KB Output is correct
43 Correct 210 ms 35300 KB Output is correct
44 Correct 217 ms 36392 KB Output is correct
45 Correct 219 ms 38052 KB Output is correct
46 Correct 225 ms 41008 KB Output is correct
47 Correct 199 ms 36656 KB Output is correct
48 Correct 180 ms 35112 KB Output is correct
49 Correct 141 ms 33072 KB Output is correct
50 Correct 136 ms 21044 KB Output is correct
51 Correct 176 ms 41064 KB Output is correct
52 Correct 173 ms 35108 KB Output is correct
53 Correct 0 ms 344 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 2 ms 604 KB Output is correct
57 Correct 2 ms 800 KB Output is correct
58 Correct 2 ms 604 KB Output is correct
59 Correct 2 ms 604 KB Output is correct
60 Correct 2 ms 604 KB Output is correct
61 Correct 2 ms 604 KB Output is correct
62 Correct 2 ms 604 KB Output is correct
63 Correct 2 ms 604 KB Output is correct
64 Correct 2 ms 604 KB Output is correct
65 Correct 2 ms 604 KB Output is correct
66 Correct 2 ms 604 KB Output is correct
67 Correct 183 ms 34788 KB Output is correct
68 Correct 148 ms 33580 KB Output is correct
69 Correct 183 ms 36992 KB Output is correct
70 Correct 190 ms 38192 KB Output is correct
71 Correct 188 ms 38232 KB Output is correct
72 Correct 209 ms 35112 KB Output is correct
73 Correct 170 ms 42428 KB Output is correct
74 Correct 142 ms 32316 KB Output is correct
75 Correct 164 ms 34088 KB Output is correct
76 Correct 153 ms 32400 KB Output is correct
77 Correct 132 ms 33580 KB Output is correct
78 Correct 138 ms 33748 KB Output is correct
79 Correct 165 ms 35112 KB Output is correct
80 Correct 142 ms 34092 KB Output is correct
81 Correct 204 ms 39516 KB Output is correct
82 Correct 245 ms 39976 KB Output is correct
83 Correct 199 ms 35116 KB Output is correct
84 Correct 146 ms 33064 KB Output is correct
85 Correct 219 ms 39864 KB Output is correct
86 Correct 190 ms 35284 KB Output is correct
87 Correct 187 ms 35208 KB Output is correct
88 Correct 160 ms 32884 KB Output is correct
89 Correct 172 ms 35112 KB Output is correct
90 Correct 214 ms 35116 KB Output is correct
91 Correct 217 ms 36192 KB Output is correct
92 Correct 222 ms 37928 KB Output is correct
93 Correct 234 ms 40988 KB Output is correct
94 Correct 230 ms 36828 KB Output is correct
95 Correct 170 ms 35116 KB Output is correct
96 Correct 145 ms 33068 KB Output is correct
97 Correct 138 ms 20800 KB Output is correct
98 Correct 182 ms 41004 KB Output is correct
99 Correct 180 ms 35096 KB Output is correct
100 Correct 84 ms 10432 KB Output is correct
101 Correct 205 ms 36648 KB Output is correct
102 Correct 178 ms 31276 KB Output is correct
103 Correct 176 ms 30004 KB Output is correct
104 Correct 208 ms 34344 KB Output is correct