이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int k_N = 5000 + 3;
const int k_M = 10000 + 3;
struct Constraint{
int l, r, k, value;
Constraint(){}
Constraint(int l, int r, int k, int value){
this->l = l;
this->r = r;
this->k = k;
this->value = value;
}
};
int n, m;
int a[k_N];
Constraint c[k_M];
int prefix[k_N];
int get_count_ones(int l, int r){
if(l == 0)
return prefix[r];
return prefix[r] - prefix[l - 1];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0; i < m; ++i)
cin >> c[i].l >> c[i].r >> c[i].k >> c[i].value;
for(int i = 0; i < m; ++i){
if(c[i].value == 1){
a[c[i].l]++;
a[c[i].r + 1]--;
}
}
int curr = 0;
for(int i = 0; i < n; ++i){
curr += a[i];
a[i] = (bool)curr;
}
prefix[0] = 0;
for(int i = 1; i < n; ++i)
prefix[i] = prefix[i - 1] + a[i];
for(int i = 0; i < m; ++i){
int count_ones = get_count_ones(c[i].l, c[i].r);
int count_zeros = (c[i].r - c[i].l + 1) - count_ones;
if(c[i].value == 0 && count_zeros >= c[i].k)
continue;
if(c[i].value == 1 && count_zeros < c[i].k)
continue;
cout << "-1\n";
return 0;
}
for(int i = 0; i < n; ++i)
cout << a[i] << " ";
cout << "\n";
}
| # | 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... |