This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define fr first
#define se second
int32_t main() {
int n, m;
cin >> n >> m;
vector<pii> r(m);
for (int i = 0; i < m; i++) {
cin >> r[i].fr >> r[i].se;
}
int ans = -1;
for (int mask = 0; mask < (1 << m); mask++) {
vector<vector<int>> qtd(2, vector<int>(n + 2));
for (int i = 0; i < m; i++) {
int w = ((mask & (1 << i)) > 0);
auto u = r[i];
qtd[w][u.fr]++;
qtd[w][u.se + 1]--;
if (u.se < u.fr) {
qtd[w][1]++;
}
}
for (int j = 0; j < 2; j++) {
for (int i = 1; i <= n; i++) {
qtd[j][i] += qtd[j][i - 1];
}
}
bool ok = 1;
for (int i = 1; i <= n; i++) {
if (!(qtd[0][i] && qtd[1][i])) ok = 0;
}
if (ok) {
ans = mask;
}
}
if (ans == -1) {
cout << "impossible\n";
} else {
for (int i = 0; i < m; i++) {
if (ans & (1 << i)) cout << "1";
else cout << "0";
}
cout << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |