# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
636874 | 2022-08-30T10:57:48 Z | ogibogi2004 | Restore Array (RMI19_restore) | C++14 | 280 ms | 668 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN=5e3+6; int A[MAXN],n,m; vector<pair<int,int> >no_zero; vector<pair<int,int> >no_one; vector<pair<int,int> >one; vector<pair<int,int> >zero; vector<pair<pair<int,int>,int> >onezero; int arr[MAXN]; bool done[2*MAXN]; int main() { memset(arr,-1,sizeof(arr)); cin>>n>>m; for(int i=0;i<m;i++) { int l,r,k,val; cin>>l>>r>>k>>val; if(k==1&&val==1)no_zero.push_back({l,r}); if(k==r-l+1&&val==1)one.push_back({l,r}); if(k==1&&val==0)zero.push_back({l,r}); if(k==r-l+1&&val==0)no_one.push_back({l,r}); } for(auto xd:no_zero) { for(int i=xd.first;i<=xd.second;i++) { arr[i]=1; } } for(auto xd:no_one) { for(int i=xd.first;i<=xd.second;i++) { if(arr[i]==1) { cout<<"-1\n"; return 0; } arr[i]=0; } } //for(int i=1;i<=n;i++)cout<<arr[i]<<" "; //cout<<endl; for(auto xd:one) { bool found=0; for(int i=xd.first;i<=xd.second;i++) { if(arr[i]==1)found=1; } if(!found)onezero.push_back({xd,1}); } for(auto xd:zero) { bool found=0; for(int i=xd.first;i<=xd.second;i++) { if(arr[i]==0)found=1; } if(!found)onezero.push_back({xd,0}); } for(int i=1;i<=n;i++) { if(arr[i]>=0)continue; int minr=n+1,what=-1; for(int j=0;j<onezero.size();j++) { if(done[j]==0&&onezero[j].first.second<minr) { minr=onezero[j].first.second; what=onezero[j].second; } } if(what==-1) { arr[i]=0; } else arr[i]=what; for(int j=0;j<onezero.size();j++) { if(onezero[j].first.first<=i&&onezero[j].first.second>=i&&onezero[j].second==arr[i]) { done[j]=1; } } } //for(int i=1;i<=n;i++)cout<<arr[i]<<" "; //cout<<endl; for(int i=0;i<onezero.size();i++) { if(done[i]==0) { cout<<"-1\n"; return 0; } } for(int i=1;i<=n;i++)cout<<arr[i]<<" "; cout<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 280 ms | 668 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 280 ms | 668 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 212 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |