답안 #1090424

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090424 2024-09-18T10:55:31 Z jamkel Stranded Far From Home (BOI22_island) C++14
100 / 100
156 ms 34132 KB
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define st first
#define nd second
typedef long long ll;
ll f(vector<ll>&u,ll i)
{
    if(u[i]==i)
    {
        return i;
    }
    u[i]=f(u,u[i]);
    return u[i];
}
void f2(vector<ll>&u,vector<ll>&w,ll i)
{
    if(u[i]==i)
    {
        w[i]=2;
        return;
    }
    if(w[i]>0)
    {
        return;
    }
    f2(u,w,u[i]);
    w[i]=w[u[i]];
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    ll n,m;
    cin>>n>>m;
    vector<ll>a(n);
    vector<pair<ll,ll>>c(n);
    vector<vector<ll>>b(n);
    vector<ll>d(n);
    for(ll i=0;i<n;i++)
    {
        cin>>c[i].st;
        c[i].nd=i;
        a[i]=c[i].st;
        d[i]=a[i];
    }
    sort(all(c));
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        b[x-1].push_back(y-1);
        b[y-1].push_back(x-1);
    }
    vector<ll>u1(n);
    vector<ll>u2(n);
    vector<bool>wyn(n,false);
    for(ll i=0;i<n;i++)
    {
        u1[i]=i;
        u2[i]=i;
    }
    for(ll q=0;q<n;q++)
    {
        ll i=c[q].nd;
        ll wag=0;
        for(ll j=0;j<b[i].size();j++)
        {
            if(f(u1,b[i][j])!=i)
            {
                if(a[b[i][j]]<a[i] or (a[b[i][j]]==a[i] && i>b[i][j]))
                {
                    if(d[f(u1,b[i][j])]<a[i])
                    {
                        wyn[f(u1,b[i][j])]=true;
                    }
                    wag+=d[u1[b[i][j]]];
                    u2[u1[b[i][j]]]=i;
                    u1[u1[b[i][j]]]=i;
                    
                }
            }
        }
        d[i]+=wag;
    }
    vector<ll>ww(n);
    for(ll i=0;i<n;i++)
    {
        ww[i]=wyn[i];
    }
    for(ll i=0;i<n;i++)
    {
        if(ww[i]==0)
        {
            f2(u2,ww,i);
        }
        cout<<ww[i]-1;
    }
    cout<<endl;
}

Compilation message

island.cpp: In function 'int main()':
island.cpp:66:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for(ll j=0;j<b[i].size();j++)
      |                    ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 616 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 1 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 90 ms 23552 KB Output is correct
4 Correct 95 ms 29012 KB Output is correct
5 Correct 92 ms 22708 KB Output is correct
6 Correct 89 ms 23352 KB Output is correct
7 Correct 98 ms 23392 KB Output is correct
8 Correct 156 ms 29780 KB Output is correct
9 Correct 106 ms 24916 KB Output is correct
10 Correct 81 ms 24084 KB Output is correct
11 Correct 97 ms 30224 KB Output is correct
12 Correct 108 ms 24152 KB Output is correct
13 Correct 90 ms 28756 KB Output is correct
14 Correct 85 ms 27984 KB Output is correct
15 Correct 83 ms 22608 KB Output is correct
16 Correct 75 ms 22212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 109 ms 22280 KB Output is correct
3 Correct 107 ms 22356 KB Output is correct
4 Correct 110 ms 28756 KB Output is correct
5 Correct 90 ms 26648 KB Output is correct
6 Correct 104 ms 22532 KB Output is correct
7 Correct 93 ms 22436 KB Output is correct
8 Correct 99 ms 22392 KB Output is correct
9 Correct 64 ms 22356 KB Output is correct
10 Correct 95 ms 25604 KB Output is correct
11 Correct 90 ms 23620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 124 ms 23892 KB Output is correct
3 Correct 114 ms 23388 KB Output is correct
4 Correct 112 ms 23636 KB Output is correct
5 Correct 133 ms 23376 KB Output is correct
6 Correct 115 ms 23268 KB Output is correct
7 Correct 87 ms 27584 KB Output is correct
8 Correct 69 ms 27220 KB Output is correct
9 Correct 76 ms 14160 KB Output is correct
10 Correct 109 ms 26448 KB Output is correct
11 Correct 89 ms 26636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 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 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 616 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 1 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 90 ms 23552 KB Output is correct
18 Correct 95 ms 29012 KB Output is correct
19 Correct 92 ms 22708 KB Output is correct
20 Correct 89 ms 23352 KB Output is correct
21 Correct 98 ms 23392 KB Output is correct
22 Correct 156 ms 29780 KB Output is correct
23 Correct 106 ms 24916 KB Output is correct
24 Correct 81 ms 24084 KB Output is correct
25 Correct 97 ms 30224 KB Output is correct
26 Correct 108 ms 24152 KB Output is correct
27 Correct 90 ms 28756 KB Output is correct
28 Correct 85 ms 27984 KB Output is correct
29 Correct 83 ms 22608 KB Output is correct
30 Correct 75 ms 22212 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 109 ms 22280 KB Output is correct
33 Correct 107 ms 22356 KB Output is correct
34 Correct 110 ms 28756 KB Output is correct
35 Correct 90 ms 26648 KB Output is correct
36 Correct 104 ms 22532 KB Output is correct
37 Correct 93 ms 22436 KB Output is correct
38 Correct 99 ms 22392 KB Output is correct
39 Correct 64 ms 22356 KB Output is correct
40 Correct 95 ms 25604 KB Output is correct
41 Correct 90 ms 23620 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 124 ms 23892 KB Output is correct
44 Correct 114 ms 23388 KB Output is correct
45 Correct 112 ms 23636 KB Output is correct
46 Correct 133 ms 23376 KB Output is correct
47 Correct 115 ms 23268 KB Output is correct
48 Correct 87 ms 27584 KB Output is correct
49 Correct 69 ms 27220 KB Output is correct
50 Correct 76 ms 14160 KB Output is correct
51 Correct 109 ms 26448 KB Output is correct
52 Correct 89 ms 26636 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 576 KB Output is correct
59 Correct 1 ms 604 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 604 KB Output is correct
62 Correct 1 ms 492 KB Output is correct
63 Correct 1 ms 604 KB Output is correct
64 Correct 1 ms 600 KB Output is correct
65 Correct 1 ms 604 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 91 ms 27984 KB Output is correct
68 Correct 83 ms 32180 KB Output is correct
69 Correct 83 ms 26904 KB Output is correct
70 Correct 86 ms 27732 KB Output is correct
71 Correct 86 ms 28004 KB Output is correct
72 Correct 108 ms 34132 KB Output is correct
73 Correct 88 ms 29200 KB Output is correct
74 Correct 68 ms 27584 KB Output is correct
75 Correct 89 ms 33660 KB Output is correct
76 Correct 105 ms 27048 KB Output is correct
77 Correct 78 ms 31752 KB Output is correct
78 Correct 87 ms 31316 KB Output is correct
79 Correct 86 ms 26876 KB Output is correct
80 Correct 68 ms 26036 KB Output is correct
81 Correct 118 ms 26736 KB Output is correct
82 Correct 111 ms 26828 KB Output is correct
83 Correct 114 ms 33236 KB Output is correct
84 Correct 80 ms 29640 KB Output is correct
85 Correct 102 ms 26884 KB Output is correct
86 Correct 103 ms 27024 KB Output is correct
87 Correct 98 ms 26960 KB Output is correct
88 Correct 86 ms 29264 KB Output is correct
89 Correct 105 ms 26644 KB Output is correct
90 Correct 127 ms 28236 KB Output is correct
91 Correct 117 ms 27864 KB Output is correct
92 Correct 129 ms 27924 KB Output is correct
93 Correct 129 ms 28244 KB Output is correct
94 Correct 109 ms 27728 KB Output is correct
95 Correct 78 ms 31940 KB Output is correct
96 Correct 70 ms 30480 KB Output is correct
97 Correct 78 ms 16712 KB Output is correct
98 Correct 97 ms 26392 KB Output is correct
99 Correct 93 ms 26704 KB Output is correct
100 Correct 33 ms 6996 KB Output is correct
101 Correct 119 ms 27968 KB Output is correct
102 Correct 120 ms 24912 KB Output is correct
103 Correct 118 ms 25936 KB Output is correct
104 Correct 120 ms 27808 KB Output is correct