제출 #198535

#제출 시각아이디문제언어결과실행 시간메모리
198535Andrei_CotorRestore Array (RMI19_restore)C++14
100 / 100
92 ms1020 KiB
#include<iostream> #include<vector> #include<deque> using namespace std; int Nr0[5005]; //cate valori 0 am in [1,i] int NrInQ[5005],InQ[5005]; vector<pair<int,int> > A[5005]; //(x,y,c) = Nr0[y]<=Nr0[x]+c int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n,m; cin>>n>>m; for(int i=1; i<=m; i++) { int st,dr,k,val; cin>>st>>dr>>k>>val; st++; dr++; if(val==0) A[dr].push_back({st-1,-k}); else A[st-1].push_back({dr,k-1}); } for(int i=1; i<=n; i++) { A[i-1].push_back({i,1}); A[i].push_back({i-1,0}); Nr0[i]=1000000000; } deque<int> Q; Q.push_back(0); InQ[0]=1; NrInQ[0]=1; while(!Q.empty()) { int nod=Q.front(); Q.pop_front(); InQ[nod]=0; for(auto other:A[nod]) { if(Nr0[other.first]>Nr0[nod]+other.second) { Nr0[other.first]=Nr0[nod]+other.second; NrInQ[other.first]++; if(NrInQ[other.first]>n || Nr0[other.first]<0) { cout<<"-1\n"; return 0; } if(InQ[other.first]) continue; Q.push_back(other.first); InQ[other.first]=1; } } } for(int i=1; i<=n; i++) { if(Nr0[i]!=Nr0[i-1]) cout<<"0 "; else cout<<"1 "; } 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...