Submission #968350

#TimeUsernameProblemLanguageResultExecution timeMemory
968350maxFedorchukStranded Far From Home (BOI22_island)C++17
15 / 100
177 ms19212 KiB
#include <bits/stdc++.h> using namespace std; const long long MX=2e5+10; long long s[MX],pr[MX]; int ans[MX]; long long get_sum(int l,int r) { return pr[r]-pr[l-1]; } bool cmp(int a,int b) { return (s[a]>s[b]); } int main() { cin.tie(0); ios_base::sync_with_stdio(0); int n,m; cin>>n>>m; for(int i=1;i<=n;i++) { cin>>s[i]; pr[i]=pr[i-1]+s[i]; } for(int i=1;i<=m;i++) { int a,b; cin>>a>>b; } vector < int > por; for(int i=1;i<=n;i++) { por.push_back(i); } sort(por.begin(),por.end(),cmp); set < int > zr; zr.insert(0); zr.insert(n+1); for(auto u:por) { auto it=zr.lower_bound(u); int rg=(*it); int lg=(*prev(it)); long long sm=get_sum(lg+1,rg-1); if((ans[rg] && sm>=s[rg]) || (ans[lg] && sm>=s[lg]) || (rg-lg>n)) { ans[u]=1; } zr.insert(u); } for(int i=1;i<=n;i++) { cout<<ans[i]; } cout<<"\n"; return 0; }
#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...