#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn5 = 2e5 + 10;
int a[maxn5], b[maxn5];
bool av[2][maxn5];
int n, m;
bool ty[maxn5];
vector <int> seg[maxn5], ex;
inline void kill(){
cout << "impossible" << endl;
exit(0);
}
inline void solve(){
for(int i = 0; i < m; i++){
seg[a[i]].pb(i);
}
int id1 = -1, id2 = -1;
for(int i = 0; i < n; i++){
if(b[id1] < i)
id1 = -1;
if(b[id2] < i)
id2 = -1;
while(!ex.empty() && b[ex.back()] < i)
ex.pop_back();
for(auto u : seg[i])
ex.pb(u);
if(id1 == -1){
if(ex.empty())
kill();
id1 = ex.back();
ty[id1] = true;
ex.pop_back();
}
while(!ex.empty() && b[ex.back()] < i)
ex.pop_back();
if(id2 == -1){
if(ex.empty())
kill();
id2 = ex.back();
ex.pop_back();
}
}
for(int i = 0; i < m; i++)
cout << ty[i];
cout << endl;
exit(0);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
}
if(max(n, m) > 20)
solve();
for(int mask = 1; mask < (1 << m) - 1; mask++){
memset(av, false, sizeof av);
for(int i = 0; i < m; i++){
int x = a[i];
while(true){
av[(mask >> i)&1][x] = true;
if(x == b[i])
break;
x++;
if(x == n)
x = 0;
}
}
bool re = true;
for(int i = 0; i < n; i++)
if(!av[0][i] || !av[1][i])
re = false;
if(re){
for(int i = 0; i < m; i++)
cout << ((mask >> i)&1);
return cout << endl, 0;
}
}
cout << "impossible" << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5324 KB |
Output is correct |
2 |
Correct |
3 ms |
5324 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
3 ms |
5324 KB |
Output is correct |
6 |
Correct |
3 ms |
5324 KB |
Output is correct |
7 |
Correct |
4 ms |
5324 KB |
Output is correct |
8 |
Correct |
4 ms |
5324 KB |
Output is correct |
9 |
Correct |
3 ms |
5324 KB |
Output is correct |
10 |
Correct |
8 ms |
5324 KB |
Output is correct |
11 |
Correct |
4 ms |
5324 KB |
Output is correct |
12 |
Correct |
6 ms |
5304 KB |
Output is correct |
13 |
Correct |
28 ms |
5324 KB |
Output is correct |
14 |
Correct |
3 ms |
5324 KB |
Output is correct |
15 |
Correct |
3 ms |
5324 KB |
Output is correct |
16 |
Correct |
39 ms |
5324 KB |
Output is correct |
17 |
Correct |
7 ms |
5324 KB |
Output is correct |
18 |
Correct |
6 ms |
5412 KB |
Output is correct |
19 |
Correct |
3 ms |
5408 KB |
Output is correct |
20 |
Correct |
3 ms |
5324 KB |
Output is correct |
21 |
Correct |
3 ms |
5324 KB |
Output is correct |
22 |
Correct |
39 ms |
5324 KB |
Output is correct |
23 |
Correct |
3 ms |
5324 KB |
Output is correct |
24 |
Correct |
7 ms |
5424 KB |
Output is correct |
25 |
Correct |
5 ms |
5328 KB |
Output is correct |
26 |
Correct |
4 ms |
5324 KB |
Output is correct |
27 |
Correct |
62 ms |
5324 KB |
Output is correct |
28 |
Correct |
3 ms |
5412 KB |
Output is correct |
29 |
Correct |
4 ms |
5408 KB |
Output is correct |
30 |
Correct |
4 ms |
5324 KB |
Output is correct |
31 |
Correct |
3 ms |
5324 KB |
Output is correct |
32 |
Correct |
3 ms |
5408 KB |
Output is correct |
33 |
Correct |
3 ms |
5324 KB |
Output is correct |
34 |
Correct |
4 ms |
5324 KB |
Output is correct |
35 |
Correct |
374 ms |
5408 KB |
Output is correct |
36 |
Correct |
22 ms |
5324 KB |
Output is correct |
37 |
Correct |
5 ms |
5324 KB |
Output is correct |
38 |
Correct |
322 ms |
5400 KB |
Output is correct |
39 |
Correct |
5 ms |
5412 KB |
Output is correct |
40 |
Correct |
4 ms |
5324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5324 KB |
Output is correct |
2 |
Correct |
3 ms |
5324 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
3 ms |
5324 KB |
Output is correct |
6 |
Correct |
3 ms |
5324 KB |
Output is correct |
7 |
Correct |
4 ms |
5324 KB |
Output is correct |
8 |
Correct |
4 ms |
5324 KB |
Output is correct |
9 |
Correct |
3 ms |
5324 KB |
Output is correct |
10 |
Correct |
8 ms |
5324 KB |
Output is correct |
11 |
Correct |
4 ms |
5324 KB |
Output is correct |
12 |
Correct |
6 ms |
5304 KB |
Output is correct |
13 |
Correct |
28 ms |
5324 KB |
Output is correct |
14 |
Correct |
3 ms |
5324 KB |
Output is correct |
15 |
Correct |
3 ms |
5324 KB |
Output is correct |
16 |
Correct |
39 ms |
5324 KB |
Output is correct |
17 |
Correct |
7 ms |
5324 KB |
Output is correct |
18 |
Correct |
6 ms |
5412 KB |
Output is correct |
19 |
Correct |
3 ms |
5408 KB |
Output is correct |
20 |
Correct |
3 ms |
5324 KB |
Output is correct |
21 |
Correct |
3 ms |
5324 KB |
Output is correct |
22 |
Correct |
39 ms |
5324 KB |
Output is correct |
23 |
Correct |
3 ms |
5324 KB |
Output is correct |
24 |
Correct |
7 ms |
5424 KB |
Output is correct |
25 |
Correct |
5 ms |
5328 KB |
Output is correct |
26 |
Correct |
4 ms |
5324 KB |
Output is correct |
27 |
Correct |
62 ms |
5324 KB |
Output is correct |
28 |
Correct |
3 ms |
5412 KB |
Output is correct |
29 |
Correct |
4 ms |
5408 KB |
Output is correct |
30 |
Correct |
4 ms |
5324 KB |
Output is correct |
31 |
Correct |
3 ms |
5324 KB |
Output is correct |
32 |
Correct |
3 ms |
5408 KB |
Output is correct |
33 |
Correct |
3 ms |
5324 KB |
Output is correct |
34 |
Correct |
4 ms |
5324 KB |
Output is correct |
35 |
Correct |
374 ms |
5408 KB |
Output is correct |
36 |
Correct |
22 ms |
5324 KB |
Output is correct |
37 |
Correct |
5 ms |
5324 KB |
Output is correct |
38 |
Correct |
322 ms |
5400 KB |
Output is correct |
39 |
Correct |
5 ms |
5412 KB |
Output is correct |
40 |
Correct |
4 ms |
5324 KB |
Output is correct |
41 |
Correct |
3 ms |
5000 KB |
Output is correct |
42 |
Incorrect |
3 ms |
5004 KB |
'impossible' claimed, but there is a solution |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5324 KB |
Output is correct |
2 |
Correct |
3 ms |
5324 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
3 ms |
5324 KB |
Output is correct |
6 |
Correct |
3 ms |
5324 KB |
Output is correct |
7 |
Correct |
4 ms |
5324 KB |
Output is correct |
8 |
Correct |
4 ms |
5324 KB |
Output is correct |
9 |
Correct |
3 ms |
5324 KB |
Output is correct |
10 |
Correct |
8 ms |
5324 KB |
Output is correct |
11 |
Correct |
4 ms |
5324 KB |
Output is correct |
12 |
Correct |
6 ms |
5304 KB |
Output is correct |
13 |
Correct |
28 ms |
5324 KB |
Output is correct |
14 |
Correct |
3 ms |
5324 KB |
Output is correct |
15 |
Correct |
3 ms |
5324 KB |
Output is correct |
16 |
Correct |
39 ms |
5324 KB |
Output is correct |
17 |
Correct |
7 ms |
5324 KB |
Output is correct |
18 |
Correct |
6 ms |
5412 KB |
Output is correct |
19 |
Correct |
3 ms |
5408 KB |
Output is correct |
20 |
Correct |
3 ms |
5324 KB |
Output is correct |
21 |
Correct |
3 ms |
5324 KB |
Output is correct |
22 |
Correct |
39 ms |
5324 KB |
Output is correct |
23 |
Correct |
3 ms |
5324 KB |
Output is correct |
24 |
Correct |
7 ms |
5424 KB |
Output is correct |
25 |
Correct |
5 ms |
5328 KB |
Output is correct |
26 |
Correct |
4 ms |
5324 KB |
Output is correct |
27 |
Correct |
62 ms |
5324 KB |
Output is correct |
28 |
Correct |
3 ms |
5412 KB |
Output is correct |
29 |
Correct |
4 ms |
5408 KB |
Output is correct |
30 |
Correct |
4 ms |
5324 KB |
Output is correct |
31 |
Correct |
3 ms |
5324 KB |
Output is correct |
32 |
Correct |
3 ms |
5408 KB |
Output is correct |
33 |
Correct |
3 ms |
5324 KB |
Output is correct |
34 |
Correct |
4 ms |
5324 KB |
Output is correct |
35 |
Correct |
374 ms |
5408 KB |
Output is correct |
36 |
Correct |
22 ms |
5324 KB |
Output is correct |
37 |
Correct |
5 ms |
5324 KB |
Output is correct |
38 |
Correct |
322 ms |
5400 KB |
Output is correct |
39 |
Correct |
5 ms |
5412 KB |
Output is correct |
40 |
Correct |
4 ms |
5324 KB |
Output is correct |
41 |
Correct |
3 ms |
5000 KB |
Output is correct |
42 |
Incorrect |
3 ms |
5004 KB |
'impossible' claimed, but there is a solution |
43 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
7780 KB |
Output is correct |
2 |
Correct |
3 ms |
5020 KB |
Output is correct |
3 |
Correct |
20 ms |
7516 KB |
Output is correct |
4 |
Correct |
17 ms |
7868 KB |
Output is correct |
5 |
Correct |
43 ms |
9236 KB |
Output is correct |
6 |
Correct |
31 ms |
9144 KB |
Output is correct |
7 |
Correct |
34 ms |
9396 KB |
Output is correct |
8 |
Correct |
5 ms |
5168 KB |
Output is correct |
9 |
Correct |
4 ms |
5036 KB |
Output is correct |
10 |
Correct |
37 ms |
9384 KB |
Output is correct |
11 |
Correct |
35 ms |
8560 KB |
Output is correct |
12 |
Correct |
38 ms |
9700 KB |
Output is correct |
13 |
Correct |
3 ms |
4940 KB |
Output is correct |
14 |
Correct |
3 ms |
4940 KB |
Output is correct |
15 |
Correct |
32 ms |
8904 KB |
Output is correct |
16 |
Correct |
13 ms |
7848 KB |
Output is correct |
17 |
Correct |
34 ms |
9408 KB |
Output is correct |
18 |
Correct |
25 ms |
8192 KB |
Output is correct |
19 |
Correct |
4 ms |
5324 KB |
Output is correct |
20 |
Correct |
39 ms |
8636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
5324 KB |
Output is correct |
2 |
Correct |
3 ms |
5324 KB |
Output is correct |
3 |
Correct |
3 ms |
5324 KB |
Output is correct |
4 |
Correct |
4 ms |
5324 KB |
Output is correct |
5 |
Correct |
3 ms |
5324 KB |
Output is correct |
6 |
Correct |
3 ms |
5324 KB |
Output is correct |
7 |
Correct |
4 ms |
5324 KB |
Output is correct |
8 |
Correct |
4 ms |
5324 KB |
Output is correct |
9 |
Correct |
3 ms |
5324 KB |
Output is correct |
10 |
Correct |
8 ms |
5324 KB |
Output is correct |
11 |
Correct |
4 ms |
5324 KB |
Output is correct |
12 |
Correct |
6 ms |
5304 KB |
Output is correct |
13 |
Correct |
28 ms |
5324 KB |
Output is correct |
14 |
Correct |
3 ms |
5324 KB |
Output is correct |
15 |
Correct |
3 ms |
5324 KB |
Output is correct |
16 |
Correct |
39 ms |
5324 KB |
Output is correct |
17 |
Correct |
7 ms |
5324 KB |
Output is correct |
18 |
Correct |
6 ms |
5412 KB |
Output is correct |
19 |
Correct |
3 ms |
5408 KB |
Output is correct |
20 |
Correct |
3 ms |
5324 KB |
Output is correct |
21 |
Correct |
3 ms |
5324 KB |
Output is correct |
22 |
Correct |
39 ms |
5324 KB |
Output is correct |
23 |
Correct |
3 ms |
5324 KB |
Output is correct |
24 |
Correct |
7 ms |
5424 KB |
Output is correct |
25 |
Correct |
5 ms |
5328 KB |
Output is correct |
26 |
Correct |
4 ms |
5324 KB |
Output is correct |
27 |
Correct |
62 ms |
5324 KB |
Output is correct |
28 |
Correct |
3 ms |
5412 KB |
Output is correct |
29 |
Correct |
4 ms |
5408 KB |
Output is correct |
30 |
Correct |
4 ms |
5324 KB |
Output is correct |
31 |
Correct |
3 ms |
5324 KB |
Output is correct |
32 |
Correct |
3 ms |
5408 KB |
Output is correct |
33 |
Correct |
3 ms |
5324 KB |
Output is correct |
34 |
Correct |
4 ms |
5324 KB |
Output is correct |
35 |
Correct |
374 ms |
5408 KB |
Output is correct |
36 |
Correct |
22 ms |
5324 KB |
Output is correct |
37 |
Correct |
5 ms |
5324 KB |
Output is correct |
38 |
Correct |
322 ms |
5400 KB |
Output is correct |
39 |
Correct |
5 ms |
5412 KB |
Output is correct |
40 |
Correct |
4 ms |
5324 KB |
Output is correct |
41 |
Correct |
3 ms |
5000 KB |
Output is correct |
42 |
Incorrect |
3 ms |
5004 KB |
'impossible' claimed, but there is a solution |
43 |
Halted |
0 ms |
0 KB |
- |