#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n,m;cin>>n>>m;
int pref[n+2] = {0};
vector<array<int,3>> v;
vector<array<int,2>> rng[n+1];
int dir[n+1] = {0};
for(int i = 0;i<m;i++){
int a,b;cin>>a>>b;
if(a<=b){
pref[a]++;
pref[b+1]--;
}else{
pref[a]++;
pref[1]++;
pref[b+1]--;
b+=n;
}
v.push_back({a,b,i});
rng[a].push_back({b,i});
}
for(int i = 2;i<=n;i++){
pref[i]+=pref[i-1];
}
for(int i = 0;i<m;i++){
for(int j = 0;j<m;j++)dir[j] = 0;
int ind = v[i][0];
int nah = v[i][1], fe = v[i][2];
bool bad = 0;
while(ind<v[i][0]+n){
if(nah==-1){
bad = 1;
break;
}
int er = nah;
dir[fe] = 1;
if(er>=v[i][0]+n){
break;
}
while(ind<=er){
ind++;
for(auto j:rng[(ind-1)%n+1]){
if(nah<(j[0]>n?j[0]:(ind<=n?j[0]:j[0]+n))){
nah = (j[0]>n?j[0]:(ind<=n?j[0]:j[0]+n));
fe = j[1];
}
}
if(pref[(ind-1)%n+1]==2)nah = -1;
}
}
if(bad==0){
for(int j = 0;j<m;j++){
cout<<dir[j];
}
return 0;
}
}
cout<<"impossible\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
10212 KB |
Output is correct |
2 |
Correct |
3 ms |
4184 KB |
Output is correct |
3 |
Incorrect |
16 ms |
7692 KB |
no wires in direction 0 between segments 1 and 1 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |