#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 1e5+10;
using pii = pair<int,int>;
vector<pair<pii, int>> wires;
bool mark[maxn][2];
int n;
void go(int l, int r, int c) { for(int i = l; i <= r; i++) mark[(i-1)%n+1][c] = 1; }
bool bom() {
for(int i = 1; i <= n; i++)
if(!mark[i][0] || !mark[i][1]) return 0;
return 1;
}
int main() {
int m; scanf("%d %d", &n, &m);
for(int i = 0, a, b; i < m; i++) {
scanf("%d %d", &a, &b);
if(b < a) b += n;
wires.push_back({{a, b}, i});
}
sort(wires.begin(), wires.end());
vector<int> ans(m);
int a = 1, b = 1, cor = 0;
for(int i = 0; i < m; i++) {
if(a > b) swap(a, b), cor ^= 1;
a = max(a, wires[i].first.second + 1);
go(wires[i].first.first, wires[i].first.second, cor);
ans[wires[i].second] = cor;
}
if(!bom()) return puts("impossible"), 0;
for(int i = 0; i < m; i++)
printf("%d", ans[i]);
puts("");
}
Compilation message
alternating.cpp: In function 'int main()':
alternating.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | int m; scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
alternating.cpp:25:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | scanf("%d %d", &a, &b);
| ~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3017 ms |
2376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
284 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Incorrect |
1 ms |
204 KB |
'impossible' claimed, but there is a solution |
5 |
Halted |
0 ms |
0 KB |
- |