Submission #714769

# Submission time Handle Problem Language Result Execution time Memory
714769 2023-03-25T09:09:38 Z Ferid20072020 Stranded Far From Home (BOI22_island) C++14
10 / 100
217 ms 31784 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(int) level(MAX);
vv(int) pref(MAX);
vv(int) parent(MAX);

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

void solve(){
    int Max = -1e9;
    cin >> n >> m;
    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);
    }
    DFS(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:78:20: 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]
   78 |     for(int i=0 ; i<Sort.size() ; i++){
      |                   ~^~~~~~~~~~~~
island.cpp:82:20: 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]
   82 |     for(int i=0 ; i<Sort.size() ; i++){
      |                   ~^~~~~~~~~~~~
island.cpp:92:9: warning: unused variable 'node' [-Wunused-variable]
   92 |     int node = 1;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 6 ms 9812 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 5 ms 9684 KB Output is correct
3 Correct 151 ms 27192 KB Output is correct
4 Correct 192 ms 27276 KB Output is correct
5 Correct 164 ms 23076 KB Output is correct
6 Correct 205 ms 23464 KB Output is correct
7 Correct 183 ms 23492 KB Output is correct
8 Correct 177 ms 23428 KB Output is correct
9 Correct 150 ms 24776 KB Output is correct
10 Correct 110 ms 23960 KB Output is correct
11 Correct 98 ms 23964 KB Output is correct
12 Correct 159 ms 23500 KB Output is correct
13 Correct 164 ms 31712 KB Output is correct
14 Correct 145 ms 31784 KB Output is correct
15 Correct 153 ms 31744 KB Output is correct
16 Correct 92 ms 31504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Incorrect 217 ms 31592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9684 KB Output is correct
2 Incorrect 198 ms 23432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9684 KB Output is correct
2 Correct 6 ms 9684 KB Output is correct
3 Correct 5 ms 9684 KB Output is correct
4 Incorrect 6 ms 9812 KB Output isn't correct
5 Halted 0 ms 0 KB -