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;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5+5;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n, m, group[MAXN];
int main() {
cin >> n >> m;
vector<pair<pii,int>> v(m);
for(int i = 0; i < m; i++) {
cin >> v[i].fr.fr >> v[i].fr.sc;
if(v[i].fr.fr > v[i].fr.sc) v[i].fr.sc += n;
v[i].sc = i;
}
sort(all(v));
auto [A,B] = v[0].fr;
bool possible = 0;
for(int i = 1; i <= 1; i++) {
// i é o primeiro elemento do 2° grupo
group[v[i].sc] = 1;
auto [C,D] = v[i].fr;
int B_ = B;
for(int j = i+1; j < sz(v); j++) {
if(B_ <= D and B_ - A < n - 1) {
if(v[j].fr.fr <= B_+1) B_ = max(B_, v[j].fr.sc);
group[v[j].sc] = 0;
}
else {
if(v[j].fr.fr <= D+1) D = max(D, v[j].fr.sc);
group[v[j].sc] = 1;
}
}
if(B_ - A >= n-1 and D - C >= n-1) {
possible = 1;
break;
}
group[v[i].sc] = 0;
if(v[i].fr.fr <= B+1) B = max(B, v[i].fr.sc);
}
if(!possible) {
cout << "impossible\n";
return 0;
}
for(int i = 0; i < m; i++) cout << group[i];
}
# | 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... |