This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
Editor: Abdelrahman Hossam
Nickname: Blobo2_Blobo2
IOI next year isA :)
*/
/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")*/
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define endl "\n"
#define all(v) v.begin(),v.end()
#define gen(arr,n,nxt) generate(arr,arr+n,nxt)
#define Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty ios_base::sync_with_stdio(false);cin.tie(0);
#define EPS 0.00000001
const int mo=1e9+7,INF=1e18;
int nxt(){int x;cin>>x;return x;}
vector<pair<int,int> >v;
int n,m;
void solve(int idx = 0,string ans = ""){
if(idx == v.size()){
int vis[n+1];
memset(vis,0,sizeof vis);
for(int i=0;i<v.size();i++){
if(ans[i] == '0'){
if(v[i].first>v[i].second){
for(int j = v[i].first;j<=n;j++)
vis[j] = (vis[j] == 2 || vis[j] == 3?3:1);
for(int j = 1;j<=v[i].second;j++)
vis[j] = (vis[j] == 2 || vis[j] == 3?3:1);
}
else{
for(int j=v[i].first;j<=v[i].second;j++)
vis[j] = (vis[j] == 2 || vis[j] == 3?3:1);
}
}
else{
if(v[i].first>v[i].second){
for(int j = v[i].first;j<=n;j++)
vis[j] = (vis[j] == 1 || vis[j] == 3?3:2);
for(int j = 1;j<=v[i].second;j++)
vis[j] = (vis[j] == 1 || vis[j] == 3?3:2);
}
else{
for(int j=v[i].first;j<=v[i].second;j++)
vis[j] = (vis[j] == 1 || vis[j] == 3?3:2);
}
}
}
bool ok=1;
for(int i=1;i<=n;i++){
ok &= (vis[i] == 3);
}
if(ok){
cout<<ans<<endl;
exit(0);
}
return;
}
solve(idx+1,ans+'0');
solve(idx+1,ans+'1');
}
signed main(){
Blobo2_el_7akim_elly_3ayz_yro7_IOI_w_3ayz_yakol_jilaty
n=nxt(),m=nxt();
for(int i=0;i<m;i++)
v.push_back({nxt(),nxt()});
solve();
cout<<"impossible";
return 0;
}
Compilation message (stderr)
alternating.cpp:21:24: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
21 | const int mo=1e9+7,INF=1e18;
| ^~~~
alternating.cpp: In function 'void solve(int, std::string)':
alternating.cpp:26:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if(idx == v.size()){
| ~~~~^~~~~~~~~~~
alternating.cpp:29:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0;i<v.size();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... |