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>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=1e5+100;
vector <pii> g[N];
ll ans[N];
int32_t main(){
ll n,m;
cin >> n >> m;
for (int i=0;i<m;i++){
ll a,b;
cin >> a >> b;
g[a].pb({b,i});
}
for (int i=1;i<=n;i++){
sort(g[i].begin(),g[i].end());
reverse(g[i].begin(),g[i].end());
}
ll cnt1=0,cnt=0;
for (int i=1;i<=n;i++){
for (int j=0;j<g[i].size();j++){
ll k=g[i][j].F;
if (cnt<cnt1){
if (cnt>=i-1){
cnt=max(cnt,k);
ans[g[i][j].S]=0;
}
continue;
}
else{
if (cnt1>=i-1){
cnt1=max(cnt1,k);
ans[g[i][j].S]=1;
}
}
}
}
if (cnt==n && cnt1==n){
for (int i=0;i<m;i++){
cout << ans[i];
}
return 0;
}
cout << "impossible" << endl;
}
Compilation message (stderr)
alternating.cpp: In function 'int32_t main()':
alternating.cpp:33:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int j=0;j<g[i].size();j++){
~^~~~~~~~~~~~
# | 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... |