QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#708529 | #8552. Sticks | ucup-team1264# | WA | 0ms | 3748kb | C++20 | 1.4kb | 2024-11-03 23:12:28 | 2024-11-03 23:12:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 998244353;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n; cin >> n;
vector<vector<char>> g(n + 1, vector<char>(n + 1));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> g[i][j];
}
}
vector cdp(n + 1, vector<array<i64, 2>>(n + 1, {0, 1}));
vector dp(n + 1, vector<i64>(n + 1, 1));
for (int i = 1; i <= n; i++) {
for (int j = n; j >= 1; j--) {
cdp[i][j] = {0, 0};
if (g[i][j] != '0') {
(cdp[i][j][1] += cdp[i - 1][j][1]) %= MOD;
}
if (g[i][j] != '1') {
(cdp[i][j][0] += cdp[i - 1][j][0] + cdp[i - 1][j][1]) %= MOD;
}
}
}
for (int i = 1; i <= n; i++) {
int len = 0;
while (len < n && g[i][len] != '0') len++;
for (int j = 1; j <= n; j++) {
dp[i][j] = 0;
if (j != 1) (dp[i][j] = dp[i][j - 1] * (cdp[i][j][0] + cdp[i][j][1])) %= MOD;
if (j - 1 <= len) {
(dp[i][j] += dp[i - 1][j - 1] * cdp[i][j][0]) %= MOD;
}
}
for (int j = 1; j <= n; j++) {
if (j <= len) {
(dp[i][j] += dp[i - 1][j]) %= MOD;
}
}
}
cout << dp[n][n] << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
2 ?? ??
output:
14
result:
ok 1 number(s): "14"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3748kb
input:
5 ??1?? ?1??0 ??0?? ???1? ??1??
output:
1576
result:
wrong answer 1st numbers differ - expected: '3144', found: '1576'