#include <bits/stdc++.h>
#define mt make_tuple
using namespace std;
typedef long long ll;
const ll INF = 1e15;
int N,M;
string ans;
vector<tuple<int,int,int,int>> q;
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//freopen("in","r",stdin);
//freopen("out","w",stdout);
cin >> N >> M;
if(N <= 18)
{
q.resize(M);
for(int i=0;i<M;i++)
{
int l,r,k,v;
cin >> l >> r >> k >> v;
q[i] = mt(l,r,k,v);
}
for(int i=0;i<(1<<N);i++)
{
string cur;
for(int k=0;k<N;k++)
cur = char('0' + !!(i&(1<<k))) + cur;
int pre[cur.size()+5];
pre[0] = (cur[0] - '0');
for(int i=1;i<cur.size();i++)
pre[i] = pre[i-1] + (cur[i] - '0');
bool flag = 1;
for(int i=0;i<M and flag;i++)
{
int l,r,k,v;
tie(l,r,k,v) = q[i];
//cout << l << " " << r << " " << k << " " << v << endl;
int onecnt = pre[r] - (l == 0 ? 0 : pre[l-1]);
if(v == 0)
flag = flag and ((r-l+1)-onecnt >= k);
else
flag = flag and ((r-l+1)-onecnt < k);
}
if(flag)
{
for(int i=0;i<cur.size();i++)
cout << int(cur[i]-'0') << " ";
return 0;
}
}
cout << -1 << endl;
}
else
{
for(int i=0;i<N;i++) ans += '2';
q.resize(M);
for(int i=0;i<M;i++)
{
int l,r,k,v;
cin >> l >> r >> k >> v;
q[i] = mt(l,r,k,v);
}
for(int i=0;i<M;i++)
{
int l,r,k,v;
tie(l,r,k,v) = q[i];
if(v == 1 and k == 1)
for(int i=l;i<=r;i++)
ans[i] = '1';
if(v == 0 and k == r-l+1)
for(int i=l;i<=r;i++)
if(ans[i] == '1')
{
cout << -1 << endl;
return 0;
}
else
ans[i] = '0';
}
for(int i=0;i<M;i++)
{
int l,r,k,v;
tie(l,r,k,v) = q[i];
if(v == 0 and k == 1)
{
bool flag = 0;
for(int i=l;i<=r;i++)
{
if(ans[i] == '0')
flag = 1;
if(ans[i] == '2' and !flag)
{
ans[i] = '0';
flag = 1;
}
}
if(!flag)
{
cout << -1 << endl;
return 0;
}
}
if(v == 1 and k == r-l+1)
{
bool flag = 0;
for(int i=l;i<=r;i++)
{
if(ans[i] == '1') flag = 1;
if(ans[i] == '2' and !flag)
{
ans[i] = '1';
flag = 1;
}
}
if(!flag)
{
cout << -1 << endl;
return 0;
}
}
}
for(int i=0;i<N;i++)
cout << (ans[i] == '2' ? '1' : ans[i]) << " ";
}
}
Compilation message
restore.cpp: In function 'int32_t main()':
restore.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for(int i=1;i<cur.size();i++)
| ~^~~~~~~~~~~
restore.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for(int i=0;i<cur.size();i++)
| ~^~~~~~~~~~~
restore.cpp:74:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
74 | if(v == 0 and k == r-l+1)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
13 ms |
364 KB |
Output is correct |
4 |
Correct |
90 ms |
364 KB |
Output is correct |
5 |
Correct |
202 ms |
396 KB |
Output is correct |
6 |
Correct |
96 ms |
364 KB |
Output is correct |
7 |
Correct |
15 ms |
364 KB |
Output is correct |
8 |
Correct |
26 ms |
364 KB |
Output is correct |
9 |
Correct |
124 ms |
396 KB |
Output is correct |
10 |
Correct |
47 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
492 KB |
Output is correct |
2 |
Correct |
59 ms |
492 KB |
Output is correct |
3 |
Correct |
57 ms |
492 KB |
Output is correct |
4 |
Correct |
56 ms |
492 KB |
Output is correct |
5 |
Correct |
5 ms |
492 KB |
Output is correct |
6 |
Correct |
16 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
492 KB |
Output is correct |
2 |
Correct |
59 ms |
492 KB |
Output is correct |
3 |
Correct |
57 ms |
492 KB |
Output is correct |
4 |
Correct |
56 ms |
492 KB |
Output is correct |
5 |
Correct |
5 ms |
492 KB |
Output is correct |
6 |
Correct |
16 ms |
492 KB |
Output is correct |
7 |
Correct |
68 ms |
620 KB |
Output is correct |
8 |
Correct |
69 ms |
492 KB |
Output is correct |
9 |
Correct |
69 ms |
492 KB |
Output is correct |
10 |
Correct |
68 ms |
620 KB |
Output is correct |
11 |
Correct |
4 ms |
492 KB |
Output is correct |
12 |
Correct |
4 ms |
492 KB |
Output is correct |
13 |
Correct |
65 ms |
492 KB |
Output is correct |
14 |
Correct |
18 ms |
492 KB |
Output is correct |
15 |
Correct |
19 ms |
492 KB |
Output is correct |
16 |
Correct |
27 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
13 ms |
364 KB |
Output is correct |
4 |
Correct |
90 ms |
364 KB |
Output is correct |
5 |
Correct |
202 ms |
396 KB |
Output is correct |
6 |
Correct |
96 ms |
364 KB |
Output is correct |
7 |
Correct |
15 ms |
364 KB |
Output is correct |
8 |
Correct |
26 ms |
364 KB |
Output is correct |
9 |
Correct |
124 ms |
396 KB |
Output is correct |
10 |
Correct |
47 ms |
364 KB |
Output is correct |
11 |
Correct |
55 ms |
492 KB |
Output is correct |
12 |
Correct |
59 ms |
492 KB |
Output is correct |
13 |
Correct |
57 ms |
492 KB |
Output is correct |
14 |
Correct |
56 ms |
492 KB |
Output is correct |
15 |
Correct |
5 ms |
492 KB |
Output is correct |
16 |
Correct |
16 ms |
492 KB |
Output is correct |
17 |
Correct |
68 ms |
620 KB |
Output is correct |
18 |
Correct |
69 ms |
492 KB |
Output is correct |
19 |
Correct |
69 ms |
492 KB |
Output is correct |
20 |
Correct |
68 ms |
620 KB |
Output is correct |
21 |
Correct |
4 ms |
492 KB |
Output is correct |
22 |
Correct |
4 ms |
492 KB |
Output is correct |
23 |
Correct |
65 ms |
492 KB |
Output is correct |
24 |
Correct |
18 ms |
492 KB |
Output is correct |
25 |
Correct |
19 ms |
492 KB |
Output is correct |
26 |
Correct |
27 ms |
492 KB |
Output is correct |
27 |
Incorrect |
4 ms |
620 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |