#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fr first
#define se second
#define t(i) ((int) s[i].size())
const int MAXN = 1e5 + 10;
vector<pii> s[MAXN];
int32_t main() {
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
s[a].push_back({b, i});
}
for (int i = 1; i <= n; i++) {
sort(s[i].begin(), s[i].end());
reverse(s[i].begin(), s[i].end());
while (t(i) > 2) s[i].pop_back();
}
vector<int> ans(m);
int zTill = -1, oTill = -1;
for (int i = 1; i <= n; i++) {
int need = 0;
if (zTill < i) {
zTill = -1;
need++;
}
if (oTill < i) {
oTill = -1;
need++;
}
if (need > t(i)) {
cout << "impossible\n";
return 0;
}
if (t(i) == 1) {
if (oTill <= zTill) {
oTill = max(oTill, s[i][0].fr);
ans[s[i][0].se] = 0;
} else {
zTill = max(zTill, s[i][0].fr);
ans[s[i][0].se] = 1;
}
} else if (t(i) == 2) {
if (oTill <= zTill) {
oTill = max(oTill, s[i][0].fr);
ans[s[i][0].se] = 0;
zTill = max(zTill, s[i][1].fr);
ans[s[i][1].se] = 1;
} else {
zTill = max(zTill, s[i][0].fr);
ans[s[i][0].se] = 1;
oTill = max(oTill, s[i][1].fr);
ans[s[i][1].se] = 0;
}
}
}
for (auto u : ans) cout << u;
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2640 KB |
'impossible' claimed, but there is a solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2640 KB |
'impossible' claimed, but there is a solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2640 KB |
'impossible' claimed, but there is a solution |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3944 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
26 ms |
4424 KB |
Output is correct |
4 |
Correct |
23 ms |
5080 KB |
Output is correct |
5 |
Correct |
46 ms |
5288 KB |
Output is correct |
6 |
Correct |
46 ms |
5192 KB |
Output is correct |
7 |
Correct |
49 ms |
6392 KB |
Output is correct |
8 |
Correct |
3 ms |
2896 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
64 ms |
6524 KB |
Output is correct |
11 |
Correct |
38 ms |
5448 KB |
Output is correct |
12 |
Correct |
41 ms |
6764 KB |
Output is correct |
13 |
Correct |
3 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2636 KB |
Output is correct |
15 |
Correct |
50 ms |
5748 KB |
Output is correct |
16 |
Correct |
23 ms |
5108 KB |
Output is correct |
17 |
Correct |
54 ms |
6216 KB |
Output is correct |
18 |
Correct |
40 ms |
5448 KB |
Output is correct |
19 |
Correct |
5 ms |
2896 KB |
Output is correct |
20 |
Correct |
41 ms |
5968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2640 KB |
'impossible' claimed, but there is a solution |
4 |
Halted |
0 ms |
0 KB |
- |