#include <iostream>
using namespace std;
int L[100004],Lp[100004],Lg[100004];
int main(){
int N,M,x,y,poc=0,cnt=0;
cin >> N >> M;
//unos dvoboja
for (int i=0;i<M;i++){
cin >> x >> y;
if (y==1){
L[x]=1;
cnt+=1;
if (cnt==1) poc=x;
else if (x<poc) poc=x;
}
else{
Lp[i-cnt]=x;
Lg[i-cnt]=y;
}
}
//traženje
for (int i=poc;i<=N;i++){
if (cnt==0) break;
if (L[i]==0){
continue;}
for (int j=0;j<M;j++){
if (Lg[j]==i && L[Lp[j]]!=1){
L[Lp[j]]=1;
cnt+=1;
if (Lp[j]<i) i=Lp[j]-1;
}
}
cnt-=1;
}
//ispis
for (int i=1;i<=N;i++){
cout << L[i];
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
10 ms |
376 KB |
Output is correct |
3 |
Correct |
287 ms |
2816 KB |
Output is correct |
4 |
Correct |
175 ms |
2532 KB |
Output is correct |
5 |
Correct |
259 ms |
2552 KB |
Output is correct |
6 |
Incorrect |
175 ms |
2684 KB |
Output isn't correct |
7 |
Correct |
192 ms |
2552 KB |
Output is correct |
8 |
Correct |
227 ms |
2756 KB |
Output is correct |
9 |
Incorrect |
106 ms |
2452 KB |
Output isn't correct |
10 |
Correct |
140 ms |
2780 KB |
Output is correct |