QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#386891 | #8330. Count off 3 | Mysterious_Cat | RE | 0ms | 0kb | C++17 | 5.8kb | 2024-04-11 21:07:01 | 2024-04-11 21:07:02 |
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][8][8][8][2];
string s;
int main() {
freopen("c.in", "r", stdin);
freopen("c.out", "w", stdout);
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];
}
}
}
}
for (int i = 0; i <= 1e4; i++) {
for (int s1 = 0; s1 < 7; s1++) {
for (int s2 = 0; s2 <= 7; s2++) {
for (int s3 = 0; s3 <= 7; s3++) {
dp[i][7][s2][s3][i & 1] = (dp[i][7][s2][s3][i & 1] + dp[i][s1][s2][s3][i & 1]) % mod;
dp[i][7][s2][s3][i & 1 ^ 1] = (dp[i][7][s2][s3][i & 1 ^ 1] + dp[i][s1][s2][s3][i & 1 ^ 1]) % mod;
}
}
}
for (int s1 = 0; s1 <= 7; s1++) {
for (int s2 = 0; s2 < 7; s2++) {
for (int s3 = 0; s3 <= 7; s3++) {
dp[i][s1][7][s3][i & 1] = (dp[i][s1][7][s3][i & 1] + dp[i][s1][s2][s3][i & 1]) % mod;
dp[i][s1][7][s3][i & 1 ^ 1] = (dp[i][s1][7][s3][i & 1 ^ 1] + dp[i][s1][s2][s3][i & 1 ^ 1]) % mod;
}
}
}
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][7][i & 1] = (dp[i][s1][s2][7][i & 1] + dp[i][s1][s2][s3][i & 1]) % mod;
dp[i][s1][s2][7][i & 1 ^ 1] = (dp[i][s1][s2][7][i & 1 ^ 1] + dp[i][s1][s2][s3][i & 1 ^ 1]) % mod;
}
}
}
}
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) {
int ans_ = ans;
for (int s1 = 0; s1 < 7; s1++) {
for (int s2 = 0; s2 < 7; s2++) {
for (int s3 = 0; s3 < 7; s3++) {
int res = 0;
for (int t1 = 0; t1 < 3; t1++) {
for (int t2 = 0; t2 < 3; t2++) {
for (int t3 = 0; t3 < 3; t3++) {
int v = -1;
int s1_ = 7;
if (t1 == 0) v *= -1;
if (t1 == 1) s1_ = (21 - sum[1][0] - sum[1][1] - s1) % 7;
if (t1 == 2) {
s1_ = (sum[1][0] + s1 - sum[1][1] + 7) % 7;
if ((sum[1][0] + sum[1][1] + s1 + s1_) % 7 == 0) {
continue;
}
}
int s2_ = 7;
if (t2 == 0) v *= -1;
if (t2 == 1) s2_ = (21 - sum[2][0] - sum[2][1] - s2) % 7;
if (t2 == 2) {
s2_ = (sum[2][0] + s2 - sum[2][1] + 7) % 7;
if ((sum[2][0] + sum[2][1] + s2 + s2_) % 7 == 0) {
continue;
}
}
int s3_ = 7;
if (t3 == 0) v *= -1;
if (t3 == 1) s3_ = (21 - sum[3][0] - sum[3][1] - s3) % 7;
if (t3 == 2) {
s3_ = (sum[3][0] + s3 - sum[3][1] + 7) % 7;
if ((sum[3][0] + sum[3][1] + s3 + s3_) % 7 == 0) {
continue;
}
}
res = ((res + v * dp[i - 1][s1_][s2_][s3_][1]) % mod + mod) % mod;
}
}
}
ans = (ans + 1ll * res * dp[i - 1][s1][s2][s3][0] % 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: 0
Dangerous Syscalls
input:
5 1 1010 110101 1000111000 101101001000