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>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
typedef double db;
typedef long long LL;
int get(){
char ch;
while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
if (ch=='-'){
int s=0;
while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
return -s;
}
int s=ch-'0';
while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
return s;
}
const int N = 2e5+5;
int n,m;
struct section{
int l,r,id;
section(const int l_=0,const int r_=0){l=l_;r=r_;}
}s[N],a[N],b[N];
int ka,kb;
bool cmp(section a,section b){return a.l!=b.l?a.l<b.l:a.r>b.r;}
int ans[N];
bool yes;
int ad1[N],ad2[N];
void dfs(int x){
if (x>m){
fo(i,1,n)ad1[i]=ad2[i]=0;
fo(i,1,m)
if (ans[i]){
ad1[s[i].l]++;
if (s[i].r>=s[i].l)ad1[s[i].r+1]--;
else ad1[1]++,ad1[s[i].r+1]--;
}
else{
ad2[s[i].l]++;
if (s[i].r>=s[i].l)ad2[s[i].r+1]--;
else ad2[1]++,ad2[s[i].r+1]--;
}
fo(i,1,n)ad1[i]+=ad1[i-1],ad2[i]+=ad2[i-1];
bool pd=1;
fo(i,1,n)pd&=(ad1[i]>0&&ad2[i]>0);
if (pd){
yes=1;
fo(i,1,m)printf("%d",ans[i]);
return;
}
return;
}
ans[x]=0;
dfs(x+1);
if (yes)return;
ans[x]=1;
dfs(x+1);
}
int main(){
n=get();m=get();
int pm=m;
fo(i,1,m){
s[i].l=get();s[i].r=get();
s[i].id=i;
}
dfs(1);
if (!yes)printf("impossible\n");
//else printf("possible\n");
return 0;
}
Compilation message (stderr)
alternating.cpp: In function 'int main()':
alternating.cpp:72:6: warning: unused variable 'pm' [-Wunused-variable]
int pm=m;
^~
# | 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... |