제출 #1136275

#제출 시각아이디문제언어결과실행 시간메모리
1136275thelegendary08Stranded Far From Home (BOI22_island)C++17
0 / 100
1097 ms24248 KiB
#include<bits/stdc++.h> #define pb push_back #define mp make_pair #define int long long #define vi vector<int> #define vvi vector<vector<int>> #define pii pair<int, int> #define vpii vector<pair<int, int>> #define vc vector<char> #define vb vector<bool> #define mii map<int,int> #define f0r(i,n) for(int i=0;i<n;i++) #define FOR(i,k,n) for(int i=k;i<n;i++) #define all(v) (v).begin(),(v).end() #define rall(v) (v).rbegin(),(v).rend() #define in(a) int a; cin>>a #define in2(a,b) int a,b; cin>>a>>b #define in3(a,b,c) int a,b,c; cin>>a>>b>>c #define in4(a,b,c,d) int a,b,c,d; cin>>a>>b>>c>>d #define vin(v,n); vi v(n); f0r(i,n){cin>>v[i];} #define out(a) cout<<a<<'\n' #define out2(a,b) cout<<a<<' '<<b<<'\n' #define out3(a,b,c) cout<<a<<' '<<b<<' '<<c<<'\n' #define out4(a,b,c,d) cout<<a<<' '<<b<<' '<<c<<' '<<d<<'\n' #define pout(a) cout<<a.first<<' '<<a.second<<'\n' #define vout(v) for(auto u : v){cout<<u<<' ';} cout<<'\n' #define dout(a) cout<<a<<' '<<#a<<'\n' #define dout2(a,b) cout<<a<<' '<<#a<<' '<<b<<' '<<#b<<'\n' #define yn(x); if(x){cout<<"YES"<<'\n';}else{cout<<"NO"<<'\n';} const int leg = 1e9 + 7; const int mod = 998244353; using namespace std; const int mxn = 2e5 + 5; int n,m; vector<int>v; vi adj[mxn]; vi et; vi st(mxn); vi sz(mxn); vi par(mxn); int timer = 0; int euler_tour(int node, int from){ par[node] = from; int ret = 1; et.pb(node); st[node] = timer; timer++; for(auto u : adj[node]){ if(u != from){ ret += euler_tour(u, node); } } sz[node] = ret; return ret; } void sub1(){ f0r(st, n){ priority_queue<pii>q; vb vis(n); vis[st] = 1; for(auto u : adj[st]){ vis[u] = 1; q.push({-v[u], u}); } int cur = v[st]; bool ok = 1; while(!q.empty()){ int node = q.top().second; q.pop(); if(v[node] > cur){ ok = 0; break; } else{ cur += v[node]; for(auto u : adj[node]){ if(vis[u])continue; vis[u] = 1; q.push({-v[u], u}); } } } cout<<ok; } } void sub2(){ euler_tour(0, -1); vi values(n); f0r(i,n){ values[i] = v[et[i]]; } vi ps(n+1); FOR(i, 1, n+1){ ps[i] = ps[i-1] + values[i-1]; } //vout(values); queue<int>q; q.push(0); vb vis(n); vis[0] = 1; vb ans(n); while(!q.empty()){ int node = q.front(); q.pop(); //dout2(node,ps[st[node] + sz[node]] - ps[st[node]]); //if(node != 0)dout(par[node]); if(node == 0 || ps[st[node] + sz[node]] - ps[st[node]] >= v[par[node]]){ ans[node] = 1; //dout(node); for(auto u : adj[node]){ if(vis[u])continue; vis[u] = 1; q.push(u); } } } f0r(i,n)cout<<ans[i]; } void sub3(){ vi ps(n+1); FOR(i, 1, n+1)ps[i] = ps[i-1] + v[i-1]; set<int>s; vpii w; f0r(i,n){ w.pb({v[i],i}); } sort(rall(w)); vb ans(n); int cur = 4e18; vi tmp; f0r(i,n){ int dex = w[i].second; int num = w[i].first; int l = -1; int r = -1; auto it = lower_bound(all(s), dex); if(it != s.end()){ r = *it; } if(it != s.begin()){ it--; l = *it; } int mn = -4e18; if(l != -1)mn = v[l]; if(r != -1){ if(mn == -4e18)mn = v[r]; else mn = min(mn, v[r]); } if(l == -1)l = 0; else l++; if(r == -1)r = n-1; else r--; //out3(dex,l,r); if(ps[r+1] - ps[l] >= mn){ ans[dex] = 1; } tmp.pb(dex); if(i != n-1 && w[i+1].first != w[i].first){ for(auto u : tmp){ s.insert(u); } tmp.clear(); } } f0r(i,n)cout<<ans[i]; cout<<'\n'; } signed main(){ ios::sync_with_stdio(false); cin.tie(NULL); //ifstream cin(".in"); //ofstream cout(".out"); cin>>n>>m; v.resize(n); f0r(i,n)cin>>v[i]; f0r(i,m){ in2(a,b); adj[--a].pb(--b); adj[b].pb(a); } /* sub1(); cout<<'\n'; sub2(); */ sub3(); /* bool s2 = 1; f0r(i, n-1){ if(v[i] < v[i+1])s2 = 0; } if(n <= 2000 && m <= 2000){ sub1(); } else if(s2){ sub2(); } else{ sub3(); } */ }
#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...