답안 #593798

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593798 2022-07-11T15:31:55 Z MohammadAghil Stranded Far From Home (BOI22_island) C++17
100 / 100
235 ms 37832 KB
#include <iostream>
#include <algorithm>
#include <functional>
#include <random>
#include <cmath>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <string>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <limits.h>
#include <tuple>
//   #pragma GCC optimization ("unroll-loops")
//  #pragma GCC optimization ("O3")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define per(i,r,l) for(int i = (r); i >= (l); i--)
  #define rep(i,l,r) for(int i = (l); i < (r); i++)
     #define all(x) begin(x), end(x)
        #define sz(x) (int)(x).size()
            #define pb push_back
                #define ss second
                     #define ff first
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = ll(1e9) + 7, maxn = 2e5 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

int par[maxn], s[maxn], vl[maxn];
ll sum[maxn], sumloc[maxn];
vector<int> tp[maxn], adj[maxn];
bool vis[maxn];

int get(int r){
    return par[r] == -1? r: par[r] = get(par[r]);
}

int main(){
    cin.tie(0) -> sync_with_stdio(0);
    int n, m; cin >> n >> m;
    rep(i,0,n) cin >> s[i], sum[i] = s[i];
    rep(i,0,m){
        int u, v; cin >> u >> v; u--, v--;
        adj[u].pb(v), adj[v].pb(u);
    }
    
    fill(par, par + n, -1);
    fill(vl, vl + n, inf);
    rep(i,0,n) tp[i].pb(i);
    
    vector<int> id(n); iota(all(id), 0), sort(all(id), [&](int i, int j){ return s[i] < s[j]; });
    
    vector<int> stk;
    for(int r: id){ vis[r] = true;
        
        if(sz(stk) && s[r] - s[stk.back()]){
            for(int t: stk) sumloc[t] = sum[get(t)];
            stk.clear();
        }
        
        for(int c: adj[r]) if(vis[c]){ c = get(c);
            if(c == r) continue;
            par[c] = r, sum[r] += sum[c];
            if(s[tp[c].back()] == s[r]){
                if(sz(tp[c]) > sz(tp[r])) swap(tp[c], tp[r]);
                for(int t: tp[c]) tp[r].pb(t);
            }else{
                for(int t: tp[c]) vl[t] = r;
            }
            tp[c].clear();
        }
        stk.pb(r);
    }
    
//    rep(i,0,n) cout << i << ' ' << get(i) << ' ' << sumloc[i] << ' ' << vl[i] << endl;
    vector<bool> ans(n);
    for(int t: tp[get(0)]) ans[t] = true;

    reverse(all(id));
    for(int r: id) if(!ans[r] && sumloc[r] >= s[vl[r]]) ans[r] = ans[vl[r]];

    for(bool c: ans) cout << c; cout << '\n';
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:88:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   88 |     for(bool c: ans) cout << c; cout << '\n';
      |     ^~~
island.cpp:88:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   88 |     for(bool c: ans) cout << c; cout << '\n';
      |                                 ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9812 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9972 KB Output is correct
10 Correct 6 ms 9892 KB Output is correct
11 Correct 7 ms 9884 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 6 ms 9940 KB Output is correct
14 Correct 6 ms 9940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9684 KB Output is correct
2 Correct 5 ms 9676 KB Output is correct
3 Correct 138 ms 28824 KB Output is correct
4 Correct 156 ms 34916 KB Output is correct
5 Correct 168 ms 29768 KB Output is correct
6 Correct 182 ms 30924 KB Output is correct
7 Correct 170 ms 31564 KB Output is correct
8 Correct 208 ms 34920 KB Output is correct
9 Correct 145 ms 31484 KB Output is correct
10 Correct 139 ms 32744 KB Output is correct
11 Correct 115 ms 33040 KB Output is correct
12 Correct 188 ms 33092 KB Output is correct
13 Correct 158 ms 35452 KB Output is correct
14 Correct 149 ms 35812 KB Output is correct
15 Correct 138 ms 32460 KB Output is correct
16 Correct 94 ms 31296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 209 ms 28808 KB Output is correct
3 Correct 190 ms 28860 KB Output is correct
4 Correct 163 ms 34820 KB Output is correct
5 Correct 142 ms 34668 KB Output is correct
6 Correct 199 ms 28836 KB Output is correct
7 Correct 153 ms 28912 KB Output is correct
8 Correct 154 ms 28908 KB Output is correct
9 Correct 90 ms 28652 KB Output is correct
10 Correct 148 ms 31212 KB Output is correct
11 Correct 170 ms 30056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 211 ms 29388 KB Output is correct
3 Correct 231 ms 32456 KB Output is correct
4 Correct 221 ms 30900 KB Output is correct
5 Correct 205 ms 36984 KB Output is correct
6 Correct 171 ms 33096 KB Output is correct
7 Correct 123 ms 33380 KB Output is correct
8 Correct 113 ms 36368 KB Output is correct
9 Correct 112 ms 22312 KB Output is correct
10 Correct 196 ms 36424 KB Output is correct
11 Correct 176 ms 31476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Correct 6 ms 9812 KB Output is correct
5 Correct 6 ms 9812 KB Output is correct
6 Correct 6 ms 9812 KB Output is correct
7 Correct 5 ms 9812 KB Output is correct
8 Correct 6 ms 9812 KB Output is correct
9 Correct 7 ms 9972 KB Output is correct
10 Correct 6 ms 9892 KB Output is correct
11 Correct 7 ms 9884 KB Output is correct
12 Correct 6 ms 9940 KB Output is correct
13 Correct 6 ms 9940 KB Output is correct
14 Correct 6 ms 9940 KB Output is correct
15 Correct 4 ms 9684 KB Output is correct
16 Correct 5 ms 9676 KB Output is correct
17 Correct 138 ms 28824 KB Output is correct
18 Correct 156 ms 34916 KB Output is correct
19 Correct 168 ms 29768 KB Output is correct
20 Correct 182 ms 30924 KB Output is correct
21 Correct 170 ms 31564 KB Output is correct
22 Correct 208 ms 34920 KB Output is correct
23 Correct 145 ms 31484 KB Output is correct
24 Correct 139 ms 32744 KB Output is correct
25 Correct 115 ms 33040 KB Output is correct
26 Correct 188 ms 33092 KB Output is correct
27 Correct 158 ms 35452 KB Output is correct
28 Correct 149 ms 35812 KB Output is correct
29 Correct 138 ms 32460 KB Output is correct
30 Correct 94 ms 31296 KB Output is correct
31 Correct 5 ms 9684 KB Output is correct
32 Correct 209 ms 28808 KB Output is correct
33 Correct 190 ms 28860 KB Output is correct
34 Correct 163 ms 34820 KB Output is correct
35 Correct 142 ms 34668 KB Output is correct
36 Correct 199 ms 28836 KB Output is correct
37 Correct 153 ms 28912 KB Output is correct
38 Correct 154 ms 28908 KB Output is correct
39 Correct 90 ms 28652 KB Output is correct
40 Correct 148 ms 31212 KB Output is correct
41 Correct 170 ms 30056 KB Output is correct
42 Correct 5 ms 9684 KB Output is correct
43 Correct 211 ms 29388 KB Output is correct
44 Correct 231 ms 32456 KB Output is correct
45 Correct 221 ms 30900 KB Output is correct
46 Correct 205 ms 36984 KB Output is correct
47 Correct 171 ms 33096 KB Output is correct
48 Correct 123 ms 33380 KB Output is correct
49 Correct 113 ms 36368 KB Output is correct
50 Correct 112 ms 22312 KB Output is correct
51 Correct 196 ms 36424 KB Output is correct
52 Correct 176 ms 31476 KB Output is correct
53 Correct 5 ms 9684 KB Output is correct
54 Correct 5 ms 9684 KB Output is correct
55 Correct 5 ms 9720 KB Output is correct
56 Correct 7 ms 9888 KB Output is correct
57 Correct 6 ms 9868 KB Output is correct
58 Correct 6 ms 9868 KB Output is correct
59 Correct 6 ms 9812 KB Output is correct
60 Correct 6 ms 9864 KB Output is correct
61 Correct 6 ms 9940 KB Output is correct
62 Correct 6 ms 9872 KB Output is correct
63 Correct 6 ms 9940 KB Output is correct
64 Correct 7 ms 9940 KB Output is correct
65 Correct 5 ms 9996 KB Output is correct
66 Correct 6 ms 9960 KB Output is correct
67 Correct 156 ms 31796 KB Output is correct
68 Correct 174 ms 35340 KB Output is correct
69 Correct 172 ms 29264 KB Output is correct
70 Correct 195 ms 30880 KB Output is correct
71 Correct 179 ms 30292 KB Output is correct
72 Correct 216 ms 34476 KB Output is correct
73 Correct 177 ms 31308 KB Output is correct
74 Correct 147 ms 30852 KB Output is correct
75 Correct 122 ms 31720 KB Output is correct
76 Correct 218 ms 32576 KB Output is correct
77 Correct 186 ms 35336 KB Output is correct
78 Correct 155 ms 34668 KB Output is correct
79 Correct 149 ms 31256 KB Output is correct
80 Correct 99 ms 32188 KB Output is correct
81 Correct 231 ms 31024 KB Output is correct
82 Correct 234 ms 31740 KB Output is correct
83 Correct 204 ms 32740 KB Output is correct
84 Correct 167 ms 36796 KB Output is correct
85 Correct 205 ms 33304 KB Output is correct
86 Correct 167 ms 33260 KB Output is correct
87 Correct 170 ms 33100 KB Output is correct
88 Correct 164 ms 32304 KB Output is correct
89 Correct 179 ms 30484 KB Output is correct
90 Correct 212 ms 31788 KB Output is correct
91 Correct 220 ms 33768 KB Output is correct
92 Correct 235 ms 34072 KB Output is correct
93 Correct 218 ms 36116 KB Output is correct
94 Correct 199 ms 33320 KB Output is correct
95 Correct 130 ms 35268 KB Output is correct
96 Correct 120 ms 35940 KB Output is correct
97 Correct 115 ms 22812 KB Output is correct
98 Correct 196 ms 37832 KB Output is correct
99 Correct 176 ms 32992 KB Output is correct
100 Correct 45 ms 13840 KB Output is correct
101 Correct 217 ms 33228 KB Output is correct
102 Correct 154 ms 28508 KB Output is correct
103 Correct 210 ms 25932 KB Output is correct
104 Correct 223 ms 28976 KB Output is correct