QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#248224 | #7623. Coloring Tape | ucup-team1198# | WA | 57ms | 3928kb | C++20 | 4.4kb | 2023-11-11 17:57:07 | 2023-11-11 17:57:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()
const int MOD = 998244353;
int add(int a, int b) {
return a + b >= MOD ? a + b - MOD : a + b;
}
const int MAXNM = 15 * 510 + 100;
vector<array<int, 2>> cond[MAXNM];
int can[MAXNM];
const int MAXN = 14;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
fill(can, can + MAXNM, 1);
int n, m, cnd;
cin >> n >> m >> cnd;
for (int i = 0; i < cnd; ++i) {
int c, x, y, d;
cin >> c >> x >> y >> d;
--c;
if (d == 0) {
if (c == 0) {
cout << "0\n";
return 0;
}
for (int i = x; i < y; ++i) {
can[c * n + i] = 0;
}
} else {
if (c == 0) {
continue;
}
cond[c].push_back({x, y});
}
}
for (int i = 1; i < m; ++i) {
sort(cond[i].begin(), cond[i].end(), [](array<int, 2> a, array<int, 2> b) {
if (a[0] == b[0]) return a[1] > b[1];
return a[0] < b[0];
});
vector<array<int, 2>> seg;
for (int t = 0; t < (int)cond[i].size(); ++t) {
bool f = true;
for (int q = 0; q < (int)cond[i].size(); ++q) {
if (t == q) continue;
if (cond[i][q] == cond[i][t] && q < t) {
f = false;
}
if (cond[i][q] == cond[i][t]) continue;
if (cond[i][q][0] >= cond[i][t][0] && cond[i][q][1] <= cond[i][t][1]) {
f = false;
}
}
if (f) {
seg.push_back(cond[i][t]);
}
}
cond[i] = seg;
}
vector<vector<int>> dp((1 << (n + 1)), vector<int>(1, 0));
dp[(1 << n) - 1][0] = 1;
int c = 0, r = n - 1;
int condl = 0, condr = 0;
for (int i = n - 1; i < n * m - 1; ++i) {
if (i == 43) {
/// cerr << " DP: " << dp[28][0] << endl;
}
/// cerr << "i: " << i << endl;
++r;
if (r == n) {
r = 0;
++c;
condl = condr = 0;
}
while (condl < (int)cond[c].size() && cond[c][condl][1] <= r) ++condl;
while (condr < (int)cond[c].size() && cond[c][condr][0] <= r) ++condr;
/// cerr << r << " : " << c << endl;
/// cerr << "borders: " << condl << " " << condr << endl;
vector<vector<int>> dp1((1 << (n + 1)), vector<int>(cond[c].size() + 1, 0));
if (r == 0) {
for (int mask = 0; mask < (1 << n); ++mask) {
if (mask & 1) {
dp1[mask][0] += dp[mask].back();
}
dp1[mask | 1 | (1 << n)][0] += dp[mask].back();
}
for (int i = 0; i < 2 * (1 << n); ++i) {
dp1[i][0] %= MOD;
}
/// cerr << dp1[(1 << n) - 1][0] << endl;
dp = move(dp1);
continue;
}
for (int mask = 0; mask < (1 << n); ++mask) {
int m1 = mask;
if (!(mask & (1 << r))) {
m1 ^= (1 << r);
}
for (int i = condl; i <= condr; ++i) {
if (dp[mask][i] == 0) continue;
if (mask & (1 << (r - 1))) {
dp1[m1 ^ (1 << (r - 1))][i] += dp[mask][i];
}
if (!can[c * n + r]) continue;
int j = condr;
if (mask & (1 << r)) {
dp1[m1][j] += dp[mask][i];
/// cerr << m1 << " " << j << " " << dp1[m1][j] << endl;
}
dp1[m1 + (1 << n)][j] += dp[mask][i];
}
}
for (int mask = (1 << n); mask < 2 * (1 << n); ++mask) {
int m0 = mask;
if (mask & (1 << r)) {
m0 ^= (1 << r);
}
for (int i = condl; i <= condr; ++i) {
if (dp[mask][i] == 0) continue;
dp1[m0][i] += dp[mask][i];
if (mask & (1 << r)) {
dp1[m0 - (1 << n)][i] += dp[mask][i];
}
}
}
dp = move(dp1);
}
int ans = 0;
for (int mask = 0; mask < (1 << n); ++mask) {
ans = add(ans, dp[mask].back() % MOD);
}
cout << ans << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3644kb
input:
3 5 3 3 2 3 0 4 1 2 0 5 1 3 0
output:
19
result:
ok 1 number(s): "19"
Test #2:
score: 0
Accepted
time: 1ms
memory: 3656kb
input:
5 10 10 9 3 4 1 2 4 5 0 7 2 3 0 9 2 3 0 6 3 5 0 6 2 4 1 2 4 5 0 1 1 3 1 7 2 4 0 10 2 3 0
output:
1514
result:
ok 1 number(s): "1514"
Test #3:
score: 0
Accepted
time: 1ms
memory: 3720kb
input:
5 10 20 8 4 5 0 2 2 5 1 8 4 5 0 10 3 5 0 7 1 3 1 1 2 4 1 6 3 5 1 10 3 5 0 4 1 5 1 7 3 4 1 2 2 4 1 8 3 4 0 9 3 5 0 5 2 5 1 9 4 5 0 9 1 2 0 6 1 5 1 8 3 5 0 2 2 4 1 8 3 5 0
output:
28131
result:
ok 1 number(s): "28131"
Test #4:
score: -100
Wrong Answer
time: 57ms
memory: 3928kb
input:
10 100 200 95 5 7 0 7 4 6 1 62 9 10 0 32 5 8 1 31 2 6 1 75 7 9 1 1 4 7 1 18 7 10 1 75 1 8 1 87 6 9 1 44 7 8 1 68 6 9 1 95 4 6 0 34 1 2 1 70 1 6 1 31 5 9 1 15 6 10 1 48 5 8 1 51 3 7 1 39 5 9 1 23 2 3 1 7 8 9 1 84 7 10 1 13 4 9 1 18 3 6 1 59 9 10 0 31 8 10 1 6 7 9 1 76 3 10 1 41 5 6 0 33 3 4 1 96 1 10...
output:
-365369858
result:
wrong answer 1st numbers differ - expected: '655333622', found: '-365369858'