QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#413746 | #8330. Count off 3 | ucup-team173 | TL | 1675ms | 137952kb | C++20 | 5.4kb | 2024-05-18 00:40:19 | 2024-05-18 00:40:19 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define db double
using namespace std;
const int Mod = 1e9 + 7;
int f[10005][7][7][7][2];
int sum[10005][8][7][7][7];
int Fpow[10005][4];
void add(int &x, int y) {
x += y, x >= Mod ? x -= Mod : 0;
}
void init() {
Fpow[0][1] = Fpow[0][2] = Fpow[0][3] = 1;
for (int i = 1; i <= 10000; i++) {
Fpow[i][1] = Fpow[i - 1][1];
Fpow[i][2] = Fpow[i - 1][2] * 2 % 7;
Fpow[i][3] = Fpow[i - 1][3] * 3 % 7;
}
f[0][0][0][0][0] = f[0][0][0][0][1] = 1;
for (int p = 1; p <= 10000; p++) {
for (int t = 0; t < 7; t++) {
for (int tt = 0; tt < 7; tt++) {
for (int ttt = 0; ttt < 7; ttt++) {
int a = (t + Fpow[p - 1][1]) % 7;
int b = (tt + Fpow[p - 1][2]) % 7;
int c = (ttt + Fpow[p - 1][3]) % 7;
if (p != 1) {
add(f[p][t][tt][ttt][p & 1], f[p - 1][t][tt][ttt][p & 1]);
}
add(f[p][a][b][c][p & 1], f[p - 1][t][tt][ttt][p & 1]);
add(f[p][t][tt][ttt][~p & 1], f[p - 1][t][tt][ttt][~p & 1]);
}
}
}
for (int sta = 0; sta < 8; sta++) {
for (int t = 0; t < 7; t++) {
for (int tt = 0; tt < 7; tt++) {
for (int ttt = 0; ttt < 7; ttt++) {
sum[p][sta][t][tt][ttt] = f[p][t][tt][ttt][1];
}
}
}
if (sta & 4) {
for (int t = 1; t < 7; t++) {
for (int tt = 0; tt < 7; tt++) {
for (int ttt = 0; ttt < 7; ttt++) {
add(sum[p][sta][t][tt][ttt], sum[p][sta][t - 1][tt][ttt]);
}
}
}
}
if (sta & 2) {
for (int t = 0; t < 7; t++) {
for (int tt = 1; tt < 7; tt++) {
for (int ttt = 0; ttt < 7; ttt++) {
add(sum[p][sta][t][tt][ttt], sum[p][sta][t][tt - 1][ttt]);
}
}
}
}
if (sta & 1) {
for (int t = 0; t < 7; t++) {
for (int tt = 0; tt < 7; tt++) {
for (int ttt = 1; ttt < 7; ttt++) {
add(sum[p][sta][t][tt][ttt], sum[p][sta][t][tt][ttt - 1]);
}
}
}
}
}
}
}
int get(int len, int a, int b, int c) {
int sta = ((a == -1) << 2) | ((b == -1) << 1) | (c == -1);
a = (a + 7) % 7, b = (b + 7) % 7, c = (c + 7) % 7;
return sum[len][sta][a][b][c];
}
int calc(int len, vector<vector<int>> val) {
int ans = 0;
for (int t = 0; t < 7; t++) {
for (int tt = 0; tt < 7; tt++) {
for (int ttt = 0; ttt < 7; ttt++) {
int now[4] = {0, t, tt, ttt};
vector<int> lim[4];
for (int p = 1; p <= 3; p++) {
int g = (now[p] + val[p][0] + 7 - val[p][1]) % 7;
int h = (7- (now[p] + val[p][0] + val[p][1]) % 7) % 7;
lim[p].push_back(-1);
lim[p].push_back(g);
if (g != h) {
lim[p].push_back(h);
}
}
int res = 0;
for (auto a : lim[1]) {
for (auto b : lim[2]) {
for (auto c : lim[3]) {
int g = 1;
if (a != -1) g = Mod - g;
if (b != -1) g = Mod - g;
if (c != -1) g = Mod - g;
res = (res + 1ll * g * get(len, a, b, c)) % Mod;
}
}
}
if (res && f[len][t][tt][ttt][0]) {
ans = (ans + 1ll * res * f[len][t][tt][ttt][0]) % Mod;
}
}
}
}
return ans;
}
bool check(vector<vector<int>> val) {
for (int i = 1; i <= 3; i++) {
if (val[i][0] == val[i][1]) {
return 0;
}
if ((val[i][0] + val[i][1]) % 7 == 0) {
return 0;
}
}
return 1;
}
void solve() {
string s;
cin >> s;
int len = s.size();
vector<vector<int>> val(4, vector<int>(2));
int ans = 0;
for (int i = 0; i < len; i++) {
if (s[i] == '1') {
if (i != len - 1) {
add(ans, calc(len - i - 1, val));
}
for (int t = 1; t <= 3; t++) {
val[t][~(len - i - 1) & 1] = (val[t][~(len - i - 1) & 1] + Fpow[len - i - 1][t]) % 7;
}
if (i == len - 1) {
if (check(val)) {
ans++;
}
}
}
}
cout << ans << '\n';
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
init();
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
/*
5
1
1010
110101
1000111000
101101001000
*/
详细
Test #1:
score: 100
Accepted
time: 71ms
memory: 137796kb
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: 0
Accepted
time: 111ms
memory: 137952kb
input:
10 1 11 1000 10111011 1000110100101001 11101110000001000011010011011000 110011000111110001101010101100100011010010101000011111001101011 11010111011101000010101111011111011011100001001101010011101011111111011011111101110110010011001101000001000111100010010111000010 10000000000000000000000000000000000...
output:
1 1 2 45 6591 814196699 193088128 849103726 497125329 363076920
result:
ok 10 numbers
Test #3:
score: 0
Accepted
time: 1130ms
memory: 137744kb
input:
10 1 101 100101000 111111001111011001111100111 100001101010101000101110010111010010001101101110011111000001010001111100101010000 111001010100100100110011110111000111001001001001000100000011000110011000110101010010100000100101110101000011000011100010011001011000101110100111000110011011010111011111011...
output:
1 2 64 27062688 486363229 184013394 580592021 118930214 772664718 344619804
result:
ok 10 numbers
Test #4:
score: 0
Accepted
time: 1675ms
memory: 137848kb
input:
10 1 1011 1101001010001110 1000010101110010000010010000000000001010111001001001110011001101 1001100101110111001000100100110111110001110010111011010101010111011101111101111100010000001100001001011100111100010110011010000010000000001100111011000001110011010000100000110101010011111100010111111100011011...
output:
1 3 10053 860833891 537931408 329471109 368911735 157523156 595487313 534701861
result:
ok 10 numbers
Test #5:
score: -100
Time Limit Exceeded
input:
10 1 11111 1010110010010000111001001 10011010100100001000110000111101101000111100001000000101010001100111111010001000101000000011100101000101100111100001001101100 11000100100010011101010101001011100010001100001010110011110101001101011000110001000111101010010000110111010001100100100111001000001000010...
output:
1 10 4692555 763463648 464152115 115362567 880780461 578723006 560068977 423846910