답안 #869485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869485 2023-11-04T12:23:19 Z lolismek Stranded Far From Home (BOI22_island) C++14
100 / 100
639 ms 58916 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 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21116 KB Output is correct
4 Correct 6 ms 21340 KB Output is correct
5 Correct 8 ms 21340 KB Output is correct
6 Correct 6 ms 21184 KB Output is correct
7 Correct 6 ms 21340 KB Output is correct
8 Correct 6 ms 21340 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 6 ms 21340 KB Output is correct
11 Correct 6 ms 21340 KB Output is correct
12 Correct 6 ms 21340 KB Output is correct
13 Correct 5 ms 21280 KB Output is correct
14 Correct 5 ms 21084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 336 ms 57860 KB Output is correct
4 Correct 162 ms 35264 KB Output is correct
5 Correct 343 ms 55860 KB Output is correct
6 Correct 324 ms 52060 KB Output is correct
7 Correct 342 ms 57536 KB Output is correct
8 Correct 229 ms 36520 KB Output is correct
9 Correct 292 ms 52332 KB Output is correct
10 Correct 289 ms 50456 KB Output is correct
11 Correct 177 ms 38276 KB Output is correct
12 Correct 196 ms 35264 KB Output is correct
13 Correct 166 ms 36660 KB Output is correct
14 Correct 207 ms 34988 KB Output is correct
15 Correct 331 ms 57080 KB Output is correct
16 Correct 280 ms 57712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 629 ms 56256 KB Output is correct
3 Correct 539 ms 51228 KB Output is correct
4 Correct 202 ms 36648 KB Output is correct
5 Correct 174 ms 35720 KB Output is correct
6 Correct 567 ms 56260 KB Output is correct
7 Correct 326 ms 58492 KB Output is correct
8 Correct 316 ms 58412 KB Output is correct
9 Correct 273 ms 57672 KB Output is correct
10 Correct 261 ms 46224 KB Output is correct
11 Correct 177 ms 36460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 21084 KB Output is correct
2 Correct 208 ms 36056 KB Output is correct
3 Correct 209 ms 36028 KB Output is correct
4 Correct 225 ms 36540 KB Output is correct
5 Correct 192 ms 35080 KB Output is correct
6 Correct 188 ms 34752 KB Output is correct
7 Correct 177 ms 38116 KB Output is correct
8 Correct 148 ms 37260 KB Output is correct
9 Correct 132 ms 30520 KB Output is correct
10 Correct 161 ms 35188 KB Output is correct
11 Correct 170 ms 37208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 21084 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21116 KB Output is correct
4 Correct 6 ms 21340 KB Output is correct
5 Correct 8 ms 21340 KB Output is correct
6 Correct 6 ms 21184 KB Output is correct
7 Correct 6 ms 21340 KB Output is correct
8 Correct 6 ms 21340 KB Output is correct
9 Correct 5 ms 21084 KB Output is correct
10 Correct 6 ms 21340 KB Output is correct
11 Correct 6 ms 21340 KB Output is correct
12 Correct 6 ms 21340 KB Output is correct
13 Correct 5 ms 21280 KB Output is correct
14 Correct 5 ms 21084 KB Output is correct
15 Correct 4 ms 21084 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 336 ms 57860 KB Output is correct
18 Correct 162 ms 35264 KB Output is correct
19 Correct 343 ms 55860 KB Output is correct
20 Correct 324 ms 52060 KB Output is correct
21 Correct 342 ms 57536 KB Output is correct
22 Correct 229 ms 36520 KB Output is correct
23 Correct 292 ms 52332 KB Output is correct
24 Correct 289 ms 50456 KB Output is correct
25 Correct 177 ms 38276 KB Output is correct
26 Correct 196 ms 35264 KB Output is correct
27 Correct 166 ms 36660 KB Output is correct
28 Correct 207 ms 34988 KB Output is correct
29 Correct 331 ms 57080 KB Output is correct
30 Correct 280 ms 57712 KB Output is correct
31 Correct 4 ms 21084 KB Output is correct
32 Correct 629 ms 56256 KB Output is correct
33 Correct 539 ms 51228 KB Output is correct
34 Correct 202 ms 36648 KB Output is correct
35 Correct 174 ms 35720 KB Output is correct
36 Correct 567 ms 56260 KB Output is correct
37 Correct 326 ms 58492 KB Output is correct
38 Correct 316 ms 58412 KB Output is correct
39 Correct 273 ms 57672 KB Output is correct
40 Correct 261 ms 46224 KB Output is correct
41 Correct 177 ms 36460 KB Output is correct
42 Correct 5 ms 21084 KB Output is correct
43 Correct 208 ms 36056 KB Output is correct
44 Correct 209 ms 36028 KB Output is correct
45 Correct 225 ms 36540 KB Output is correct
46 Correct 192 ms 35080 KB Output is correct
47 Correct 188 ms 34752 KB Output is correct
48 Correct 177 ms 38116 KB Output is correct
49 Correct 148 ms 37260 KB Output is correct
50 Correct 132 ms 30520 KB Output is correct
51 Correct 161 ms 35188 KB Output is correct
52 Correct 170 ms 37208 KB Output is correct
53 Correct 4 ms 21080 KB Output is correct
54 Correct 4 ms 21080 KB Output is correct
55 Correct 4 ms 21084 KB Output is correct
56 Correct 6 ms 21340 KB Output is correct
57 Correct 6 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 6 ms 21340 KB Output is correct
61 Correct 5 ms 21180 KB Output is correct
62 Correct 6 ms 21340 KB Output is correct
63 Correct 6 ms 21396 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 21080 KB Output is correct
67 Correct 313 ms 57812 KB Output is correct
68 Correct 168 ms 35384 KB Output is correct
69 Correct 308 ms 56040 KB Output is correct
70 Correct 298 ms 51948 KB Output is correct
71 Correct 329 ms 57204 KB Output is correct
72 Correct 206 ms 36716 KB Output is correct
73 Correct 286 ms 52584 KB Output is correct
74 Correct 242 ms 50624 KB Output is correct
75 Correct 154 ms 38360 KB Output is correct
76 Correct 178 ms 35264 KB Output is correct
77 Correct 151 ms 36540 KB Output is correct
78 Correct 155 ms 35080 KB Output is correct
79 Correct 298 ms 57076 KB Output is correct
80 Correct 257 ms 57788 KB Output is correct
81 Correct 506 ms 56404 KB Output is correct
82 Correct 443 ms 51136 KB Output is correct
83 Correct 199 ms 36892 KB Output is correct
84 Correct 150 ms 35784 KB Output is correct
85 Correct 552 ms 56720 KB Output is correct
86 Correct 334 ms 58428 KB Output is correct
87 Correct 331 ms 58444 KB Output is correct
88 Correct 299 ms 46272 KB Output is correct
89 Correct 196 ms 36576 KB Output is correct
90 Correct 248 ms 36032 KB Output is correct
91 Correct 236 ms 36032 KB Output is correct
92 Correct 282 ms 36668 KB Output is correct
93 Correct 273 ms 37628 KB Output is correct
94 Correct 262 ms 36800 KB Output is correct
95 Correct 197 ms 40640 KB Output is correct
96 Correct 168 ms 38936 KB Output is correct
97 Correct 146 ms 32216 KB Output is correct
98 Correct 196 ms 36800 KB Output is correct
99 Correct 207 ms 38844 KB Output is correct
100 Correct 89 ms 27012 KB Output is correct
101 Correct 521 ms 54688 KB Output is correct
102 Correct 206 ms 36300 KB Output is correct
103 Correct 459 ms 50112 KB Output is correct
104 Correct 639 ms 58916 KB Output is correct