QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#387272 | #8330. Count off 3 | Mysterious_Cat | WA | 11ms | 30772kb | C++17 | 4.2kb | 2024-04-12 11:36:12 | 2024-04-12 11:36:12 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 5;
const int mod = 1e9 + 7;
int n, ans, sum[4][2], pw[N][7], dp[N][7][7][7][2], f[5][5][5][2];
string s;
int m7(int x) {
x %= 7;
return min(x, 7 - x);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
for (int j = 1; j <= 6; j++) {
pw[0][j] = 1;
}
dp[0][0][0][0][1] = 1;
dp[0][1][1][1][0] = 1;
for (int i = 1; i <= (int)1e4; i++) {
for (int j = 1; j <= 6; j++) {
pw[i][j] = 1ll * pw[i - 1][j] * j % 7;
}
for (int s1 = 0; s1 < 7; s1++) {
for (int s2 = 0; s2 < 7; s2++) {
for (int s3 = 0; s3 < 7; s3++) {
dp[i][s1][s2][s3][i & 1] = (dp[i - 1][s1][s2][s3][i & 1] + dp[i - 1][(s1 - pw[i][1] + 7) % 7][(s2 - pw[i][2] + 7) % 7][(s3 - pw[i][3] + 7) % 7][i & 1]) % mod;
dp[i][s1][s2][s3][i & 1 ^ 1] = dp[i - 1][s1][s2][s3][i & 1 ^ 1];
}
}
}
}
int T;
cin >> T;
while (T--) {
cin >> s;
n = s.size();
ans = 0;
reverse(s.begin(), s.end());
memset(sum, 0, sizeof(sum));
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1') {
if (i > 0) {
memset(f, 0, sizeof(f));
for (int s1 = 0; s1 < 7; s1++) {
for (int s2 = 0; s2 < 7; s2++) {
for (int s3 = 0; s3 < 7; s3++) {
f[m7(s1 + sum[1][0])][m7(s2 + sum[2][0])][m7(s3 + sum[3][0])][0] = (f[m7(s1 + sum[1][0])][m7(s2 + sum[2][0])][m7(s3 + sum[3][0])][0] + dp[i - 1][s1][s2][s3][0]);
f[m7(s1 + sum[1][1])][m7(s2 + sum[2][1])][m7(s3 + sum[3][1])][1] = (f[m7(s1 + sum[1][1])][m7(s2 + sum[2][1])][m7(s3 + sum[3][1])][1] + dp[i - 1][s1][s2][s3][1]);
}
}
}
for (int t1 = 0; t1 < 4; t1++) {
for (int t2 = 0; t2 <= 4; t2++) {
for (int t3 = 0; t3 <= 4; t3++) {
f[4][t2][t3][0] = (f[4][t2][t3][0] + f[t1][t2][t3][0]) % mod;
f[4][t2][t3][1] = (f[4][t2][t3][1] + f[t1][t2][t3][1]) % mod;
}
}
}
for (int t1 = 0; t1 <= 4; t1++) {
for (int t2 = 0; t2 < 4; t2++) {
for (int t3 = 0; t3 <= 4; t3++) {
f[t1][4][t3][0] = (f[t1][4][t3][0] + f[t1][t2][t3][0]) % mod;
f[t1][4][t3][1] = (f[t1][4][t3][1] + f[t1][t2][t3][1]) % mod;
}
}
}
for (int t1 = 0; t1 <= 4; t1++) {
for (int t2 = 0; t2 <= 4; t2++) {
for (int t3 = 0; t3 < 4; t3++) {
f[t1][t2][4][0] = (f[t1][t2][4][0] + f[t1][t2][t3][0]) % mod;
f[t1][t2][4][1] = (f[t1][t2][4][1] + f[t1][t2][t3][1]) % mod;
}
}
}
for (int t1 = 0; t1 <= 4; t1++) {
for (int t2 = 0; t2 <= 4; t2++) {
for (int t3 = 0; t3 <= 4; t3++) {
ans = (((ans + ((t1 < 4) + (t2 < 4) + (t3 < 4) & 1 ? -1ll : 1ll) * f[t1][t2][t3][0] * f[t1][t2][t3][1] % mod) % mod + mod) % mod);
}
}
}
}
for (int j = 1; j <= 3; j++) {
sum[j][i & 1] = (sum[j][i & 1] + pw[i][j]) % 7;
}
if (i == 0) {
bool flag = 1;
for (int j = 1; j <= 3; j++) {
flag &= (sum[j][0] + sum[j][1]) % 7 && (sum[j][0] - sum[j][1] + 7) % 7;
}
ans += flag;
}
}
}
cout << ans << '\n';
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 11ms
memory: 30772kb
input:
5 1 1010 110101 1000111000 101101001000
output:
1 2 15 114 514
result:
ok 5 number(s): "1 2 15 114 514"
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 30704kb
input:
10 1 11 1000 10111011 1000110100101001 11101110000001000011010011011000 110011000111110001101010101100100011010010101000011111001101011 11010111011101000010101111011111011011100001001101010011101011111111011011111101110110010011001101000001000111100010010111000010 10000000000000000000000000000000000...
output:
1 1 2 45 6591 814196699 193088128 598830109 900398660 41939272
result:
wrong answer 8th numbers differ - expected: '849103726', found: '598830109'