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 f first
#define s second
#define m_p make_pair
#define vec vector
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fast_rmi ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#pragma GCC optimize("Ofast")
using namespace std;
typedef pair<int,int> pii;
const int N=5e3+1;
vec<int> g[2*N],gr[2*N];
void add_edge(int v,int u,int x,int y){
if(x)
v+=N;
if(y)
u+=N;
g[v].pb(u);
gr[u].pb(v);
}
bool u[2*N];
int c[2*N],tt=1;
vec<int>ord;
void dfs1(int v){
u[v]=1;
for(auto &z :g[v]){
if(!u[z])
dfs1(z);
}
ord.pb(v);
}
void dfs2(int v){
c[v]=tt;
for(auto &z : gr[v]){
if(!c[z])
dfs2(z);
}
}
signed main(){
fast_rmi;
int n,m;
cin>>n>>m;
vec<array<int,4>>arr(m);
for(auto &z : arr){
cin>>z[0]>>z[1]>>z[2]>>z[3];
if(z[3]==1)
z[2]=z[2]-1;
}
auto brute=[&](){
for(int mask=0;mask<(1<<n);mask++){
vec<int>a(n);
for(int i=0;i<n;i++){
if(mask&(1<<i))
a[i]=1;
else
a[i]=0;
}
auto check=[&](){
int ok=1;
for(auto &z : arr){
int cnt=0;
for(int i=z[0];i<=z[1];i++)
cnt+=(!a[i]);
if(z[3])
ok&=(cnt<=z[2]);
else{
ok&=(cnt>=z[2]);
}
}
return ok;
};
if(check()){
return a;
}
}
return vec<int>();
};
if(n<=18){
vec<int> ans=brute();
if(!sz(ans)){
cout<<-1;
return 0;
}
for(auto &z : ans)
cout<<z<<' ';
return 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... |