QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#123978 | #87. Devil's Share | Qwerty1232# | 0 | 2ms | 3748kb | C++17 | 3.2kb | 2023-07-14 02:24:37 | 2024-07-04 00:38:39 |
Judging History
answer
#include <bits/stdc++.h>
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, m;
std::cin >> n >> m;
std::vector<std::array<int, 4>> input(m);
for (auto& [l, r, k, val] : input) {
std::cin >> l >> r >> k >> val;
r++;
k--;
}
auto check = [&](std::vector<int> ans) {
bool fail = false;
for (auto& [l, r, k, val] : input) {
int sum = std::accumulate(ans.begin() + l, ans.begin() + r, 0);
if (val == 0) {
fail = fail || ((r - l) - sum <= k);
} else {
fail = fail || (sum < (r - l) - k);
}
if (fail) {
break;
}
}
return !fail;
};
if (n <= 18) {
for (int mask = 0; mask < (1 << n); mask++) {
std::vector<int> ans(n);
for (int j = 0; j < n; j++) {
ans[j] = (mask >> j) & 1;
}
if (check(ans)) {
for (int i = 0; i < n; i++) {
std::cout << ans[i] << " \n"[i == n - 1];
}
return 0;
}
}
std::cout << "-1\n";
return 0;
}
std::vector<int> ans(n, -1);
std::array<std::vector<int>, 3> prf;
auto recalc = [&]() {
for (int i = 0; i < 3; i++) {
prf[i].assign(n + 1, 0);
for (int j = 0; j < n; j++) {
prf[i][j + 1] = prf[i][j] + (ans[j] == i - 1);
}
}
};
auto get = [&](int c, int l, int r) {
return prf[c + 1][r] - prf[c + 1][l];
};
while (true) {
recalc();
bool fail = false;
for (auto& [l, r, k, val] : input) {
if (val == 0 && get(0, l, r) > k) {
l = r = k = val = -1;
continue;
}
if (val == 0 && get(1, l, r) >= (r - l - k)) {
l = r = k = val = -1;
continue;
}
if (get(-1, l, r) == 0) {
std::cout << "-1\n";
return 0;
}
if (val == 0 && k == r - l - 1 || val == 1 && k == 0) {
for (int i = l; i < r; i++) {
if (ans[i] >= 0 && ans[i] != val) {
std::cout << "-1\n";
return 0;
}
ans[i] = val;
}
l = r = k = val = -1;
fail = true;
break;
}
if (get(-1, l, r) == 1) {
int it = std::find(ans.begin() + l, ans.begin() + r, -1) - ans.begin();
ans[it] = val;
l = r = k = val = -1;
fail = true;
break;
}
}
input.erase(std::find(input.begin(), input.end(), std::array<int, 4>{-1, -1, -1, -1}), input.end());
if (!fail) {
for (int i = 0; i < n; i++) {
std::cout << std::max(0, ans[i]) << " \n"[i == n - 1];
}
return 0;
}
}
return 0;
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3516kb
input:
1536 4 2 1 2 2 0 0 0 0 0 2 3 2 3 3 0 0 0 0 0 3 1 2 0 3 0 0 0 0 0 4 2 2 3 2 0 0 0 0 0 1 3 3 2 2 0 0 0 0 0 3 1 2 2 0 0 0 0 0 0 3 2 1 2 3 0 0 0 0 0 6 1 3 3 0 0 0 0 0 0 4 1 0 1 2 0 0 0 0 0 4 2 1 2 3 0 0 0 0 0 4 2 3 0 2 0 0 0 0 0 5 3 2 3 3 0 0 0 0 0 3 2 2 1 1 0 0 0 0 0 3 2 3 2 0 0 0 0 0 0 8 1 3 1 3 0 0 0...
output:
-1
result:
FAIL Condition failed: "s.length() == S"
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 2ms
memory: 3748kb
input:
35960 2 0 0 5 2 0 0 17 0 7 2 0 6 0 15 0 0 0 4 5 2 3 0 0 1 20 0 0 0 8 2 0 5 0 0 15 0 5 7 0 2 0 0 2 11 0 0 4 0 10 2 0 14 0 0 11 0 0 6 1 2 0 0 10 3 0 0 8 0 1 2 0 1 9 0 2 0 0 6 0 2 0 0 0 0 5 0 12 7 3 2 0 0 5 0 0 2 0 8 9 2 7 2 0 0 0 0 0 6 8 2 0 0 0 4 1 0 3 18 0 2 0 0 14 4 8 0 0 0 1 2 0 2 0 0 0 13 3 9 0 2...
output:
2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
FAIL Condition failed: "s.length() == S"
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 1ms
memory: 3664kb
input:
26488 21 7 19 0 0 0 0 0 0 0 3 15 21 0 0 0 0 0 0 0 7 4 35 0 0 0 0 0 0 0 5 28 12 0 0 0 0 0 0 0 22 40 3 0 0 0 0 0 0 0 1 7 6 0 0 0 0 0 0 0 5 12 21 0 0 0 0 0 0 0 18 27 13 0 0 0 0 0 0 0 2 36 6 0 0 0 0 0 0 0 15 19 14 0 0 0 0 0 0 0 34 17 20 0 0 0 0 0 0 0 11 17 5 0 0 0 0 0 0 0 19 10 12 0 0 0 0 0 0 0 28 29 9 ...
output:
7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
FAIL Condition failed: "s.length() == S"
Subtask #4:
score: 0
Skipped
Dependency #1:
0%