답안 #714780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
714780 2023-03-25T09:14:12 Z Ferid20072020 Stranded Far From Home (BOI22_island) C++14
20 / 100
218 ms 38096 KB
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2,fma")
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll          long long 
#define ull         unsigned long long 
#define ld          long double 
#define ui          unsigned int 
#define f           first
#define s           second
#define ins         insert
#define pb          push_back
#define mp          make_pair
#define ln          '\n'
#define int         ll
#define pii         pair<int , int> 
#define INF         LLONG_MAX
#define vv(a)       vector<a>
#define pp(a, b)    pair<a, b>
#define pq(a)       priority_queue<a>
#define qq(a)       queue<a>
#define ss(a)       set<a>
#define mss(a)      multiset<a>
#define mm(a, b)    map<a, b>
#define mmm(a , b)  multimap<a , b>
#define sz(x)       (x).size()
#define all(x)      (x).begin() , (x).end()
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

const int MAX = 2e5 + 3;
int n , m;
int tot[MAX];
vv(vv(int)) g(MAX);
vv(vv(pii)) g1(MAX);
vv(int) color(MAX);
vv(int) level(MAX);
vv(int) pref(MAX);
vv(int) parent(MAX);
int cnt = 0 , total = 0;

void init(){
    cnt = 1;
    total = 0;
    for(int i=1 ; i<MAX ; i++){
        color[i] = 0;
    }
}
 
void DFS(int src){
    //cout << src << ln;
    color[src] = 1;
    for(auto to : g1[src]){
        if(color[to.s] == 0 && to.f <= total){
            cnt++;
            total += to.f;
            DFS(to.s);
        }
    }
}

void DFS1(int src , int lvl){
    level[src] = lvl;
    for(auto to : g[src]){
        if(to > src){
            parent[to] = src;
            DFS1(to , lvl+1);
        }
    }
}

void solve(){
    int Max = -1e9;
    cin >> n >> m;
    if(n <= 2000 && m <= 2000){
        for(int i=1 ; i<=n ; i++){
            cin >> tot[i];
        }
        for(int i=0 ; i<m ; i++){
            int u , v;
            cin >> u >> v;
            g1[u].pb({tot[v] , v});
            g1[v].pb({tot[u] , u});
        }
        for(int i=1 ; i<=n ; i++){
            sort(all(g1[i]));
        }
        for(int i=1 ; i<=n ; i++){
            init();
            total = tot[i];
            DFS(i);
            while(cnt < n){
                int cnt1 = cnt;
                for(int j=1 ; j<=n ; j++){
                    if(color[j] == 1){
                        DFS(j);
                    }
                }
                if(cnt == cnt1){
                    break;
                }
            }
            if(cnt == n){
                cout << 1;
            }
            else{
                cout << 0;
            }
        }
    }
    else{
        for(int i=1 ; i<=n ; i++){
            cin >> tot[i];
            Max = max(Max , tot[i]);
            pref[i] = tot[i];
        }
        for(int i=0 ; i<m ; i++){
            int u , v;
            cin >> u >> v;
            g[u].pb(v);
            g[v].pb(u);
        }
        DFS1(1 , 1);
        vv(pii) Sort;
        for(int i=1 ; i<=n ; i++){
            Sort.pb({level[i] , i});
        }
        sort(all(Sort));
        reverse(all(Sort));
        for(int i=0 ; i<Sort.size() ; i++){
            pref[parent[Sort[i].s]] += pref[Sort[i].s];
        }
        reverse(all(Sort));
        for(int i=0 ; i<Sort.size() ; i++){
            if(tot[parent[Sort[i].s]] <= pref[Sort[i].s]){
                pref[Sort[i].s] = pref[parent[Sort[i].s]];
            }
        }
        //for(int i=1 ; i<=n ; i++){
        //    cout << pref[i] << ln;
        //}
        vv(int) ans(n+3 , 0);
        ans[1] = 1;
        int node = 1;
        for(int i=2 ; i<=n ; i++){
            if(pref[i] >= Max){
                ans[i] = 1;
            }
        }
        for(int i=1 ; i<=n ; i++){
            cout << ans[i];
        }
    }
}
 
 
signed main(){
    fastio
 
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
 
    return 0;
}

Compilation message

island.cpp: In function 'void solve()':
island.cpp:138:24: 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]
  138 |         for(int i=0 ; i<Sort.size() ; i++){
      |                       ~^~~~~~~~~~~~
island.cpp:142:24: 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]
  142 |         for(int i=0 ; i<Sort.size() ; i++){
      |                       ~^~~~~~~~~~~~
island.cpp:152:13: warning: unused variable 'node' [-Wunused-variable]
  152 |         int node = 1;
      |             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15956 KB Output is correct
2 Correct 10 ms 15956 KB Output is correct
3 Correct 8 ms 15956 KB Output is correct
4 Correct 130 ms 16160 KB Output is correct
5 Correct 128 ms 16084 KB Output is correct
6 Correct 128 ms 16084 KB Output is correct
7 Correct 110 ms 16124 KB Output is correct
8 Correct 116 ms 16116 KB Output is correct
9 Correct 129 ms 16084 KB Output is correct
10 Correct 118 ms 16164 KB Output is correct
11 Correct 126 ms 16092 KB Output is correct
12 Correct 109 ms 16084 KB Output is correct
13 Correct 184 ms 16160 KB Output is correct
14 Correct 128 ms 16104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15948 KB Output is correct
2 Correct 8 ms 15956 KB Output is correct
3 Correct 154 ms 33444 KB Output is correct
4 Correct 171 ms 33412 KB Output is correct
5 Correct 187 ms 29232 KB Output is correct
6 Correct 168 ms 29728 KB Output is correct
7 Correct 218 ms 29752 KB Output is correct
8 Correct 202 ms 29788 KB Output is correct
9 Correct 138 ms 31032 KB Output is correct
10 Correct 102 ms 30156 KB Output is correct
11 Correct 106 ms 30236 KB Output is correct
12 Correct 168 ms 29940 KB Output is correct
13 Correct 134 ms 38096 KB Output is correct
14 Correct 147 ms 38008 KB Output is correct
15 Correct 169 ms 38076 KB Output is correct
16 Correct 101 ms 37776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15956 KB Output is correct
2 Incorrect 141 ms 37968 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15956 KB Output is correct
2 Incorrect 160 ms 29584 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 15956 KB Output is correct
2 Correct 10 ms 15956 KB Output is correct
3 Correct 8 ms 15956 KB Output is correct
4 Correct 130 ms 16160 KB Output is correct
5 Correct 128 ms 16084 KB Output is correct
6 Correct 128 ms 16084 KB Output is correct
7 Correct 110 ms 16124 KB Output is correct
8 Correct 116 ms 16116 KB Output is correct
9 Correct 129 ms 16084 KB Output is correct
10 Correct 118 ms 16164 KB Output is correct
11 Correct 126 ms 16092 KB Output is correct
12 Correct 109 ms 16084 KB Output is correct
13 Correct 184 ms 16160 KB Output is correct
14 Correct 128 ms 16104 KB Output is correct
15 Correct 9 ms 15948 KB Output is correct
16 Correct 8 ms 15956 KB Output is correct
17 Correct 154 ms 33444 KB Output is correct
18 Correct 171 ms 33412 KB Output is correct
19 Correct 187 ms 29232 KB Output is correct
20 Correct 168 ms 29728 KB Output is correct
21 Correct 218 ms 29752 KB Output is correct
22 Correct 202 ms 29788 KB Output is correct
23 Correct 138 ms 31032 KB Output is correct
24 Correct 102 ms 30156 KB Output is correct
25 Correct 106 ms 30236 KB Output is correct
26 Correct 168 ms 29940 KB Output is correct
27 Correct 134 ms 38096 KB Output is correct
28 Correct 147 ms 38008 KB Output is correct
29 Correct 169 ms 38076 KB Output is correct
30 Correct 101 ms 37776 KB Output is correct
31 Correct 9 ms 15956 KB Output is correct
32 Incorrect 141 ms 37968 KB Output isn't correct
33 Halted 0 ms 0 KB -