답안 #869480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869480 2023-11-04T12:21:01 Z lolismek Stranded Far From Home (BOI22_island) C++14
100 / 100
621 ms 58724 KB
    #include <algorithm>
    #include <iostream>
    #include <fstream>
    #include <vector>
    #include <queue>
    #include <map>

    #define int long long

    #define pii pair <int, int>


    using namespace std;

    //ifstream fin("input.in");
    //ofstream fout("output.out");

    #define fin cin
    #define fout cout

    const int NMAX = 2e5;

    int v[NMAX + 1];
    vector <int> adj[NMAX + 1];

    int par[NMAX + 1];
    int sum[NMAX + 1];

    int Find(int x){
        if(x == par[x]){
            return x;
        }
        return par[x] = Find(par[x]);
    }

    void Join(int x, int y){
        x = Find(x);
        y = Find(y);

        if(x == y){
            return;
        }

        par[x] = y;
        sum[y] += sum[x];
    }

    bool ins[NMAX + 1];

    void Insert(int x){
        ins[x] = true;
        for(int vec : adj[x]){
            if(ins[vec]){
                Join(vec, x);
            }
        }
    }

    bool ans[NMAX + 1];

    vector <int> inds[NMAX + 1];

    int wher[NMAX + 1];
    vector <int> quer[NMAX + 1];

    signed main(){

        int n, m;
        fin >> n >> m;

        priority_queue <pii, vector <pii>, greater <pii>> pq;

        vector <int> vals;
        for(int i = 1; i <= n; i++){
            fin >> v[i];
            par[i] = i;
            sum[i] = v[i];
            vals.push_back(v[i]);
            ans[i] = 1;
        }

        for(int i = 1; i <= m; i++){
            int a, b;
            fin >> a >> b;
            adj[a].push_back(b);
            adj[b].push_back(a);
        }

        sort(vals.begin(), vals.end());
        vals.erase(unique(vals.begin(), vals.end()), vals.end());

        map <int, int> norm;
        for(int i = 0; i < (int)vals.size(); i++){
            norm[vals[i]] = i;
        }

        for(int i = 1; i <= n; i++){
            inds[norm[v[i]]].push_back(i);
            quer[norm[v[i]]].push_back(i);
            wher[i] = norm[v[i]];
        }

        for(int val = 0; val < (int)vals.size(); val++){
            for(int ind : inds[val]){
                Insert(ind);
            }

            for(int x : quer[val]){
                int s = sum[Find(x)];
                int st = 0, dr = (int)vals.size() - 1, a = 0;
                while(st <= dr){
                    int mid = (st + dr) / 2;
                    if(vals[mid] <= s){
                        a = mid;
                        st = mid + 1;
                    }else{
                        dr = mid - 1;
                    }
                }

                if(a > val){
                    wher[x] = a;
                    quer[a].push_back(x);
                }
            }
        }

        for(int i = 1; i <= n; i++){
            if(wher[i] == (int)vals.size() - 1){
                fout << 1;
            }else{
                fout << 0;
            }
        }

        return 0;
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 3 ms 20916 KB Output is correct
4 Correct 6 ms 21340 KB Output is correct
5 Correct 6 ms 21340 KB Output is correct
6 Correct 5 ms 21084 KB Output is correct
7 Correct 6 ms 21208 KB Output is correct
8 Correct 6 ms 21372 KB Output is correct
9 Correct 5 ms 21188 KB Output is correct
10 Correct 7 ms 21340 KB Output is correct
11 Correct 6 ms 21340 KB Output is correct
12 Correct 6 ms 21408 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 343 ms 57916 KB Output is correct
4 Correct 166 ms 35264 KB Output is correct
5 Correct 372 ms 56008 KB Output is correct
6 Correct 310 ms 51996 KB Output is correct
7 Correct 396 ms 57272 KB Output is correct
8 Correct 209 ms 36640 KB Output is correct
9 Correct 321 ms 52604 KB Output is correct
10 Correct 265 ms 50604 KB Output is correct
11 Correct 153 ms 38332 KB Output is correct
12 Correct 187 ms 35240 KB Output is correct
13 Correct 179 ms 36600 KB Output is correct
14 Correct 165 ms 35136 KB Output is correct
15 Correct 314 ms 57032 KB Output is correct
16 Correct 282 ms 57608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 21084 KB Output is correct
2 Correct 621 ms 56128 KB Output is correct
3 Correct 547 ms 51232 KB Output is correct
4 Correct 208 ms 36652 KB Output is correct
5 Correct 150 ms 35804 KB Output is correct
6 Correct 597 ms 56432 KB Output is correct
7 Correct 342 ms 58724 KB Output is correct
8 Correct 338 ms 58552 KB Output is correct
9 Correct 259 ms 57652 KB Output is correct
10 Correct 273 ms 46332 KB Output is correct
11 Correct 182 ms 36544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 218 ms 36020 KB Output is correct
3 Correct 219 ms 36168 KB Output is correct
4 Correct 232 ms 36724 KB Output is correct
5 Correct 195 ms 35040 KB Output is correct
6 Correct 224 ms 34736 KB Output is correct
7 Correct 189 ms 38076 KB Output is correct
8 Correct 152 ms 37236 KB Output is correct
9 Correct 132 ms 30664 KB Output is correct
10 Correct 161 ms 35856 KB Output is correct
11 Correct 165 ms 37132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21080 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 3 ms 20916 KB Output is correct
4 Correct 6 ms 21340 KB Output is correct
5 Correct 6 ms 21340 KB Output is correct
6 Correct 5 ms 21084 KB Output is correct
7 Correct 6 ms 21208 KB Output is correct
8 Correct 6 ms 21372 KB Output is correct
9 Correct 5 ms 21188 KB Output is correct
10 Correct 7 ms 21340 KB Output is correct
11 Correct 6 ms 21340 KB Output is correct
12 Correct 6 ms 21408 KB Output is correct
13 Correct 5 ms 21084 KB Output is correct
14 Correct 5 ms 21084 KB Output is correct
15 Correct 5 ms 21084 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 343 ms 57916 KB Output is correct
18 Correct 166 ms 35264 KB Output is correct
19 Correct 372 ms 56008 KB Output is correct
20 Correct 310 ms 51996 KB Output is correct
21 Correct 396 ms 57272 KB Output is correct
22 Correct 209 ms 36640 KB Output is correct
23 Correct 321 ms 52604 KB Output is correct
24 Correct 265 ms 50604 KB Output is correct
25 Correct 153 ms 38332 KB Output is correct
26 Correct 187 ms 35240 KB Output is correct
27 Correct 179 ms 36600 KB Output is correct
28 Correct 165 ms 35136 KB Output is correct
29 Correct 314 ms 57032 KB Output is correct
30 Correct 282 ms 57608 KB Output is correct
31 Correct 6 ms 21084 KB Output is correct
32 Correct 621 ms 56128 KB Output is correct
33 Correct 547 ms 51232 KB Output is correct
34 Correct 208 ms 36652 KB Output is correct
35 Correct 150 ms 35804 KB Output is correct
36 Correct 597 ms 56432 KB Output is correct
37 Correct 342 ms 58724 KB Output is correct
38 Correct 338 ms 58552 KB Output is correct
39 Correct 259 ms 57652 KB Output is correct
40 Correct 273 ms 46332 KB Output is correct
41 Correct 182 ms 36544 KB Output is correct
42 Correct 4 ms 21084 KB Output is correct
43 Correct 218 ms 36020 KB Output is correct
44 Correct 219 ms 36168 KB Output is correct
45 Correct 232 ms 36724 KB Output is correct
46 Correct 195 ms 35040 KB Output is correct
47 Correct 224 ms 34736 KB Output is correct
48 Correct 189 ms 38076 KB Output is correct
49 Correct 152 ms 37236 KB Output is correct
50 Correct 132 ms 30664 KB Output is correct
51 Correct 161 ms 35856 KB Output is correct
52 Correct 165 ms 37132 KB Output is correct
53 Correct 4 ms 21084 KB Output is correct
54 Correct 4 ms 21084 KB Output is correct
55 Correct 4 ms 21084 KB Output is correct
56 Correct 6 ms 21340 KB Output is correct
57 Correct 7 ms 21340 KB Output is correct
58 Correct 5 ms 21084 KB Output is correct
59 Correct 6 ms 21340 KB Output is correct
60 Correct 5 ms 21340 KB Output is correct
61 Correct 5 ms 21188 KB Output is correct
62 Correct 6 ms 21340 KB Output is correct
63 Correct 6 ms 21340 KB Output is correct
64 Correct 6 ms 21340 KB Output is correct
65 Correct 5 ms 21080 KB Output is correct
66 Correct 5 ms 21084 KB Output is correct
67 Correct 326 ms 57948 KB Output is correct
68 Correct 170 ms 35264 KB Output is correct
69 Correct 323 ms 56024 KB Output is correct
70 Correct 297 ms 52020 KB Output is correct
71 Correct 369 ms 57052 KB Output is correct
72 Correct 230 ms 36512 KB Output is correct
73 Correct 326 ms 52376 KB Output is correct
74 Correct 273 ms 50664 KB Output is correct
75 Correct 156 ms 38336 KB Output is correct
76 Correct 182 ms 35156 KB Output is correct
77 Correct 150 ms 36732 KB Output is correct
78 Correct 217 ms 34916 KB Output is correct
79 Correct 306 ms 57080 KB Output is correct
80 Correct 257 ms 57736 KB Output is correct
81 Correct 570 ms 56072 KB Output is correct
82 Correct 489 ms 51132 KB Output is correct
83 Correct 202 ms 36796 KB Output is correct
84 Correct 158 ms 36044 KB Output is correct
85 Correct 595 ms 56316 KB Output is correct
86 Correct 353 ms 58452 KB Output is correct
87 Correct 325 ms 58452 KB Output is correct
88 Correct 308 ms 46180 KB Output is correct
89 Correct 210 ms 36880 KB Output is correct
90 Correct 243 ms 35952 KB Output is correct
91 Correct 212 ms 36056 KB Output is correct
92 Correct 229 ms 36520 KB Output is correct
93 Correct 196 ms 35004 KB Output is correct
94 Correct 227 ms 34740 KB Output is correct
95 Correct 177 ms 37968 KB Output is correct
96 Correct 149 ms 37308 KB Output is correct
97 Correct 166 ms 30456 KB Output is correct
98 Correct 172 ms 35076 KB Output is correct
99 Correct 166 ms 37056 KB Output is correct
100 Correct 84 ms 25684 KB Output is correct
101 Correct 485 ms 52380 KB Output is correct
102 Correct 200 ms 33980 KB Output is correct
103 Correct 409 ms 47612 KB Output is correct
104 Correct 525 ms 56400 KB Output is correct