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 ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 16;
int N,M;
pii arr[mxn];
int ans = -1;
vector<int> paths[mxn];
int col[mxn];
bool inside(pii r,int p){
if(r.fs<=r.sc){
if(r.fs<=p&&p<=r.sc)return true;
else return false;
}
else{
if(p<=r.fs||p>=r.sc)return true;
else return false;
}
}
bool banana(int a,int b){
pii ta = arr[a],tb = arr[b];
if(inside(ta,tb.fs)||inside(ta,tb.sc)||inside(tb,ta.fs)||inside(tb,ta.sc))return true;
else return false;
}
void dfs(int now,int c = 1){
col[now] = c;
for(auto nxt:paths[now]){
if(col[nxt]&&col[nxt] != -c){
cout<<"impossible\n";
exit(0);
}
if(!col[nxt])dfs(nxt,-c);
}
return;
}
vector<int> peko[mxn];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M;
for(int i = 0;i<M;i++){
cin>>arr[i].fs>>arr[i].sc;
arr[i].fs--,arr[i].sc--;
int k = arr[i].fs;
while(k != arr[i].sc){
peko[k].push_back(i);
k = (k+1)%N;
}
peko[k].push_back(i);
}
for(int i = 0;i<N;i++){
if(peko[i].size() == 2){
int a = peko[i][0],b = peko[i][1];
paths[a].push_back(b);
paths[b].push_back(a);
}
if(peko[i].size() < 2){
cout<<"impossible\n";
return 0;
}
}
for(int i = 0;i<M;i++){
if(!col[i])dfs(i);
}
for(int i = 0;i<(1<<M);i++){
int dp[mxn] = {};
for(int j = 0;j<M;j++){
int k;
for(k = arr[j].fs;k != arr[j].sc;k = (k+1)%N){
dp[k] |= 1<<(i&(1<<j)?1:0);
}
dp[k] |= 1<<(i&(1<<j)?1:0);
}
if(*min_element(dp,dp+N) == 3)ans = i;
}
if(ans == -1)assert(false);
else{
for(int i = 0;i<M;i++){
if(ans&(1<<i))cout<<1;
else cout<<0;
}
}
return 0;
}
# | 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... |