#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define sz(a) (int)a.size()
bool check(vector<int>& a, vector<array<int,4>>& q)
{
int n = sz(a), m = sz(q);
vector<int> p(n);
forn(i, n){
p[i] = a[i];
if(i)p[i] += p[i - 1];
}
bool ok = true;
for(int i = 0;i < m;++i){
int l = q[i][0], r = q[i][1], k = q[i][2], val = q[i][3];
int zeroes = (r - l + 1) - p[r];
if(l)zeroes += p[l - 1];
int number = 0;
if(zeroes >= k)number = 0;
else number = 1;
if(number != val)ok = false;
}
return ok;
}
void solve()
{
int n, m;
cin >> n >> m;
vector<array<int, 4>> q(m);
for(int i = 0;i < m;++i){
int l, r, k, val;
cin >> l >> r >> k >> val;
q[i] = {l, r, k, val};
}
if(n <= 18)
{
for(int mask = 0;mask < (1 << n);++mask){
vector<int> a(n, 0);
vector<int> p(n, 0);
for(int i = 0;i < n;++i){
if(mask & (1 << i))a[i] = 1;
p[i] = a[i];
if(i)p[i] += p[i - 1];
}
if(check(a, q)){
forn(i, n)cout << a[i] << " ";
cout << "\n";
return;
}
}
cout << "-1\n";
return;
}
vector<int> a(n, 0);
for(int i = 0;i < m;++i){
int l = q[i][0], r = q[i][1], k = q[i][2], val = q[i][3];
if(k == 1){
if(val == 1){
for(int j = l;j <= r;++j)
a[j] = 1;
}
}else if(k == r - l + 1){
if(val == 0){
for(int j = l;j <= r;++j)
a[j] = 0;
}
}
}
if(check(a, q)){
forn(i, n)cout << a[i] << " ";
return;
}
cout << "-1\n";
}
int32_t main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
//cin >> t;
while(t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
35 ms |
204 KB |
Output is correct |
4 |
Correct |
30 ms |
204 KB |
Output is correct |
5 |
Correct |
130 ms |
292 KB |
Output is correct |
6 |
Correct |
63 ms |
220 KB |
Output is correct |
7 |
Correct |
27 ms |
204 KB |
Output is correct |
8 |
Correct |
23 ms |
204 KB |
Output is correct |
9 |
Correct |
130 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
460 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
3 ms |
460 KB |
Output is correct |
4 |
Correct |
3 ms |
460 KB |
Output is correct |
5 |
Correct |
4 ms |
460 KB |
Output is correct |
6 |
Correct |
5 ms |
484 KB |
Output is correct |
7 |
Incorrect |
4 ms |
480 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
35 ms |
204 KB |
Output is correct |
4 |
Correct |
30 ms |
204 KB |
Output is correct |
5 |
Correct |
130 ms |
292 KB |
Output is correct |
6 |
Correct |
63 ms |
220 KB |
Output is correct |
7 |
Correct |
27 ms |
204 KB |
Output is correct |
8 |
Correct |
23 ms |
204 KB |
Output is correct |
9 |
Correct |
130 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
3 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
3 ms |
460 KB |
Output is correct |
14 |
Correct |
3 ms |
460 KB |
Output is correct |
15 |
Correct |
4 ms |
460 KB |
Output is correct |
16 |
Correct |
5 ms |
484 KB |
Output is correct |
17 |
Incorrect |
4 ms |
480 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |