Submission #593787

#TimeUsernameProblemLanguageResultExecution timeMemory
593787MohammadAghilStranded Far From Home (BOI22_island)C++17
25 / 100
1061 ms524288 KiB
#include <iostream> #include <algorithm> #include <functional> #include <random> #include <cmath> #include <vector> #include <array> #include <set> #include <map> #include <queue> #include <cassert> #include <string> #include <bitset> #include <numeric> #include <iomanip> #include <limits.h> #include <tuple> // #pragma GCC optimization ("unroll-loops") // #pragma GCC optimization ("O3") // #pragma GCC target ("avx2") using namespace std; typedef long long ll; typedef pair<int, int> pp; #define per(i,r,l) for(int i = (r); i >= (l); i--) #define rep(i,l,r) for(int i = (l); i < (r); i++) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define pb push_back #define ss second #define ff first //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll mod = 10321, maxn = 2e5, lg = 22, M = 12299390, inf = ll(1e9) + 5; ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;} int par[maxn], s[maxn], vl[maxn]; ll sum[maxn], sumloc[maxn]; vector<int> tp[maxn], adj[maxn]; bool vis[maxn]; int get(int r){ return par[r] == -1? r: par[r] = get(par[r]); } int main(){ cin.tie(0) -> sync_with_stdio(0); int n, m; cin >> n >> m; rep(i,0,n) cin >> s[i], sum[i] = s[i]; rep(i,0,m){ int u, v; cin >> u >> v; u--, v--; adj[u].pb(v), adj[v].pb(u); } fill(par, par + n, -1); fill(vl, vl + n, inf); rep(i,0,n) tp[i].pb(i); vector<int> id(n); iota(all(id), 0), sort(all(id), [&](int i, int j){ return s[i] < s[j]; }); vector<int> stk; for(int r: id){ vis[r] = true; if(sz(stk) && s[r] - s[stk.back()]){ for(int t: stk) sumloc[t] = sum[get(t)]; stk.clear(); } for(int c: adj[r]) if(vis[c]){ c = get(c); if(c == r) continue; par[c] = r, sum[r] += sum[c]; for(int t: tp[c]) if(s[t] == s[r]) tp[r].pb(t); else vl[t] = r; tp[c].clear(); } stk.pb(r); } // rep(i,0,n) cout << i << ' ' << get(i) << ' ' << sumloc[i] << ' ' << vl[i] << endl; vector<bool> ans(n); for(int t: tp[get(0)]) ans[t] = true; reverse(all(id)); for(int r: id) if(!ans[r] && sumloc[r] >= s[vl[r]]) ans[r] = ans[vl[r]]; for(bool c: ans) cout << c; cout << '\n'; return 0; }

Compilation message (stderr)

island.cpp: In function 'int main()':
island.cpp:84:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   84 |     for(bool c: ans) cout << c; cout << '\n';
      |     ^~~
island.cpp:84:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   84 |     for(bool c: ans) cout << c; cout << '\n';
      |                                 ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...