답안 #1104459

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104459 2024-10-23T20:33:33 Z alexdd Stranded Far From Home (BOI22_island) C++17
100 / 100
642 ms 173524 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
int n,m;
int a[200005];
vector<int> con[200005];

int root[200005];
set<int> s[200005],s2[200005];
int sum[200005];
void unite(int x, int y)
{
    x = root[x];
    y = root[y];
    if(x==y)
        return;
    if((int)s2[x].size() < (int)s2[y].size())
        swap(x,y);
    sum[x] += sum[y];
    for(auto it:s[y])
    {
        s[x].insert(it);
    }
    for(auto it:s2[y])
    {
        s2[x].insert(it);
        root[it] = x;
    }
    //cout<<x<<" "<<sum[x]<<" new sum\n";
}
int get_mic(int x, int lim)
{
    if(s[x].upper_bound(lim)==s[x].end())
        return INF;
    return *s[x].upper_bound(lim);
}
int poz[200005];
bool rez[200005];
int from[200005];
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>m;
    vector<pair<int,int>> ord;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        ord.push_back({a[i],i});
    }
    int u,v;
    for(int i=1;i<=m;i++)
    {
        cin>>u>>v;
        con[u].push_back(v);
        con[v].push_back(u);
    }
    sort(ord.begin(), ord.end());
    for(int i=0;i<ord.size();i++)
        poz[ord[i].second] = i;
    for(int i=1;i<=n;i++)
    {
        sum[i] = a[i];
        root[i] = i;
        s2[i].insert(i);
        for(int adj:con[i])
        {
            if(poz[adj] > poz[i])
                s[i].insert(poz[adj]);
        }
    }
    for(auto [_,i]:ord)
    {
        //cout<<i<<" ord\n";
        if(poz[i]==n-1)
        {
            rez[i]=1;
            continue;
        }
        for(int adj:con[i])
        {
            if(poz[adj] < poz[i])
            {
                unite(adj,i);
                //cout<<i<<" "<<adj<<" uneste\n";
            }
        }
        int y = ord[get_mic(root[i],poz[i])].second;
        if(sum[root[i]] >= a[y])
        {
            from[i] = y;
        }
        else
        {
            from[i] = -1;
            //cout<<i<<" "<<sum[root[i]]<<" sum\n";
        }
    }
    for(int j=n-2;j>=0;j--)
    {
        int i = ord[j].second;
        if(from[i]==-1)
            rez[i] = 0;
        else
            rez[i] = rez[from[i]];
    }
    for(int i=1;i<=n;i++)
        cout<<rez[i];
    return 0;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:59:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<ord.size();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 31056 KB Output is correct
2 Correct 5 ms 31224 KB Output is correct
3 Correct 5 ms 31056 KB Output is correct
4 Correct 8 ms 31824 KB Output is correct
5 Correct 9 ms 31936 KB Output is correct
6 Correct 7 ms 31568 KB Output is correct
7 Correct 7 ms 31712 KB Output is correct
8 Correct 7 ms 31568 KB Output is correct
9 Correct 6 ms 31568 KB Output is correct
10 Correct 7 ms 32080 KB Output is correct
11 Correct 8 ms 32080 KB Output is correct
12 Correct 9 ms 32168 KB Output is correct
13 Correct 7 ms 31568 KB Output is correct
14 Correct 8 ms 31956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 31056 KB Output is correct
2 Correct 5 ms 31056 KB Output is correct
3 Correct 244 ms 87328 KB Output is correct
4 Correct 248 ms 80980 KB Output is correct
5 Correct 482 ms 127160 KB Output is correct
6 Correct 514 ms 136744 KB Output is correct
7 Correct 487 ms 134636 KB Output is correct
8 Correct 310 ms 81192 KB Output is correct
9 Correct 498 ms 173524 KB Output is correct
10 Correct 124 ms 62648 KB Output is correct
11 Correct 321 ms 81592 KB Output is correct
12 Correct 421 ms 97448 KB Output is correct
13 Correct 234 ms 79948 KB Output is correct
14 Correct 230 ms 81848 KB Output is correct
15 Correct 234 ms 79948 KB Output is correct
16 Correct 197 ms 79500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 31056 KB Output is correct
2 Correct 527 ms 148328 KB Output is correct
3 Correct 600 ms 155780 KB Output is correct
4 Correct 274 ms 82616 KB Output is correct
5 Correct 278 ms 79992 KB Output is correct
6 Correct 642 ms 153016 KB Output is correct
7 Correct 280 ms 80056 KB Output is correct
8 Correct 256 ms 80060 KB Output is correct
9 Correct 218 ms 79372 KB Output is correct
10 Correct 188 ms 77752 KB Output is correct
11 Correct 289 ms 96956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 31224 KB Output is correct
2 Correct 554 ms 111800 KB Output is correct
3 Correct 546 ms 121204 KB Output is correct
4 Correct 621 ms 131512 KB Output is correct
5 Correct 537 ms 122344 KB Output is correct
6 Correct 409 ms 102328 KB Output is correct
7 Correct 255 ms 77244 KB Output is correct
8 Correct 198 ms 81592 KB Output is correct
9 Correct 228 ms 66752 KB Output is correct
10 Correct 517 ms 130652 KB Output is correct
11 Correct 264 ms 91376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 31056 KB Output is correct
2 Correct 5 ms 31224 KB Output is correct
3 Correct 5 ms 31056 KB Output is correct
4 Correct 8 ms 31824 KB Output is correct
5 Correct 9 ms 31936 KB Output is correct
6 Correct 7 ms 31568 KB Output is correct
7 Correct 7 ms 31712 KB Output is correct
8 Correct 7 ms 31568 KB Output is correct
9 Correct 6 ms 31568 KB Output is correct
10 Correct 7 ms 32080 KB Output is correct
11 Correct 8 ms 32080 KB Output is correct
12 Correct 9 ms 32168 KB Output is correct
13 Correct 7 ms 31568 KB Output is correct
14 Correct 8 ms 31956 KB Output is correct
15 Correct 5 ms 31056 KB Output is correct
16 Correct 5 ms 31056 KB Output is correct
17 Correct 244 ms 87328 KB Output is correct
18 Correct 248 ms 80980 KB Output is correct
19 Correct 482 ms 127160 KB Output is correct
20 Correct 514 ms 136744 KB Output is correct
21 Correct 487 ms 134636 KB Output is correct
22 Correct 310 ms 81192 KB Output is correct
23 Correct 498 ms 173524 KB Output is correct
24 Correct 124 ms 62648 KB Output is correct
25 Correct 321 ms 81592 KB Output is correct
26 Correct 421 ms 97448 KB Output is correct
27 Correct 234 ms 79948 KB Output is correct
28 Correct 230 ms 81848 KB Output is correct
29 Correct 234 ms 79948 KB Output is correct
30 Correct 197 ms 79500 KB Output is correct
31 Correct 5 ms 31056 KB Output is correct
32 Correct 527 ms 148328 KB Output is correct
33 Correct 600 ms 155780 KB Output is correct
34 Correct 274 ms 82616 KB Output is correct
35 Correct 278 ms 79992 KB Output is correct
36 Correct 642 ms 153016 KB Output is correct
37 Correct 280 ms 80056 KB Output is correct
38 Correct 256 ms 80060 KB Output is correct
39 Correct 218 ms 79372 KB Output is correct
40 Correct 188 ms 77752 KB Output is correct
41 Correct 289 ms 96956 KB Output is correct
42 Correct 6 ms 31224 KB Output is correct
43 Correct 554 ms 111800 KB Output is correct
44 Correct 546 ms 121204 KB Output is correct
45 Correct 621 ms 131512 KB Output is correct
46 Correct 537 ms 122344 KB Output is correct
47 Correct 409 ms 102328 KB Output is correct
48 Correct 255 ms 77244 KB Output is correct
49 Correct 198 ms 81592 KB Output is correct
50 Correct 228 ms 66752 KB Output is correct
51 Correct 517 ms 130652 KB Output is correct
52 Correct 264 ms 91376 KB Output is correct
53 Correct 5 ms 31056 KB Output is correct
54 Correct 4 ms 31056 KB Output is correct
55 Correct 4 ms 31240 KB Output is correct
56 Correct 7 ms 31824 KB Output is correct
57 Correct 7 ms 31864 KB Output is correct
58 Correct 6 ms 31736 KB Output is correct
59 Correct 7 ms 31568 KB Output is correct
60 Correct 6 ms 31568 KB Output is correct
61 Correct 5 ms 31568 KB Output is correct
62 Correct 7 ms 32080 KB Output is correct
63 Correct 7 ms 32012 KB Output is correct
64 Correct 7 ms 32080 KB Output is correct
65 Correct 6 ms 31592 KB Output is correct
66 Correct 9 ms 31824 KB Output is correct
67 Correct 290 ms 87224 KB Output is correct
68 Correct 233 ms 81080 KB Output is correct
69 Correct 490 ms 129464 KB Output is correct
70 Correct 536 ms 134072 KB Output is correct
71 Correct 538 ms 135860 KB Output is correct
72 Correct 337 ms 81032 KB Output is correct
73 Correct 545 ms 173496 KB Output is correct
74 Correct 132 ms 62648 KB Output is correct
75 Correct 339 ms 81568 KB Output is correct
76 Correct 465 ms 98272 KB Output is correct
77 Correct 261 ms 81664 KB Output is correct
78 Correct 266 ms 81728 KB Output is correct
79 Correct 275 ms 82360 KB Output is correct
80 Correct 209 ms 79576 KB Output is correct
81 Correct 565 ms 150696 KB Output is correct
82 Correct 563 ms 153272 KB Output is correct
83 Correct 268 ms 82616 KB Output is correct
84 Correct 231 ms 82592 KB Output is correct
85 Correct 515 ms 153016 KB Output is correct
86 Correct 252 ms 80056 KB Output is correct
87 Correct 263 ms 82616 KB Output is correct
88 Correct 189 ms 79800 KB Output is correct
89 Correct 298 ms 96840 KB Output is correct
90 Correct 565 ms 111800 KB Output is correct
91 Correct 535 ms 119984 KB Output is correct
92 Correct 621 ms 132792 KB Output is correct
93 Correct 565 ms 119736 KB Output is correct
94 Correct 492 ms 101048 KB Output is correct
95 Correct 282 ms 79544 KB Output is correct
96 Correct 219 ms 81520 KB Output is correct
97 Correct 254 ms 66692 KB Output is correct
98 Correct 599 ms 130488 KB Output is correct
99 Correct 297 ms 91320 KB Output is correct
100 Correct 75 ms 45384 KB Output is correct
101 Correct 631 ms 125040 KB Output is correct
102 Correct 380 ms 85176 KB Output is correct
103 Correct 422 ms 88176 KB Output is correct
104 Correct 498 ms 103412 KB Output is correct