QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#413753#8330. Count off 3ucup-team173TL 1790ms70824kbC++205.6kb2024-05-18 01:09:122024-05-18 01:09:13

Judging History

你现在查看的是最新测评结果

  • [2024-05-18 01:09:13]
  • 评测
  • 测评结果:TL
  • 用时:1790ms
  • 内存:70824kb
  • [2024-05-18 01:09:12]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define db double

using namespace std;

const int Mod = 1e9 + 7;

int f[5005][7][7][7][2];
int sum[5005][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 = 0; p <= 5000; p++) {
        if (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][1]) % 7;
                        int b = (tt + Fpow[(p - 1) << 1][2]) % 7;
                        int c = (ttt + Fpow[(p - 1) << 1][3]) % 7;
                        if (p != 1) add(f[p][t][tt][ttt][0], f[p - 1][t][tt][ttt][0]);
                        add(f[p][a][b][c][0], f[p - 1][t][tt][ttt][0]);

                        a = (t + Fpow[(p << 1) - 1][1]) % 7;
                        b = (tt + Fpow[(p << 1) - 1][2]) % 7;
                        c = (ttt + Fpow[(p << 1) - 1][3]) % 7;
                        add(f[p][t][tt][ttt][1], f[p - 1][t][tt][ttt][1]);
                        add(f[p][a][b][c][1], f[p - 1][t][tt][ttt][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 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[3] = {t, tt, ttt};
                vector<int> lim[3];
                for (int p = 0; 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);
                    }
                }
                ll res = 0;
                for (auto a : lim[0]) {
                    for (auto b : lim[1]) {
                        for (auto c : lim[2]) {   
                            int sta = ((a == -1) << 2) | ((b == -1) << 1) | (c == -1);
                            int p = (a != -1) ^ (b != -1) ^ (c != -1);
                            if (p) res -= sum[len >> 1][sta][(a + 7) % 7][(b + 7) % 7][(c + 7) % 7];
                            else res += sum[len >> 1][sta][(a + 7) % 7][(b + 7) % 7][(c + 7) % 7];
                        }
                    }
                }
                res = (res % Mod + Mod) % Mod;
                if (res && f[(len + 1) >> 1][t][tt][ttt][0]) {
                    ans = (ans + 1ll * res * f[(len + 1) >> 1][t][tt][ttt][0]) % Mod;
                }
            }
        }
    }
    return ans;
}

bool check(vector<vector<int>> val) {
    for (int i = 0; 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(3, 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 = 0; t < 3; t++) {
                    val[t][(len - i - 1) & 1] = (val[t][(len - i - 1) & 1] + Fpow[len - i - 1][t + 1]) % 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: 38ms
memory: 70720kb

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: 83ms
memory: 70728kb

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: 989ms
memory: 70696kb

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: 1483ms
memory: 70756kb

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: 0
Accepted
time: 1790ms
memory: 70824kb

input:

10
1
11111
1010110010010000111001001
10011010100100001000110000111101101000111100001000000101010001100111111010001000101000000011100101000101100111100001001101100
11000100100010011101010101001011100010001100001010110011110101001101011000110001000111101010010000110111010001100100100111001000001000010...

output:

1
10
4692555
763463648
464152115
115362567
880780461
578723006
560068977
423846910

result:

ok 10 numbers

Test #6:

score: -100
Time Limit Exceeded

input:

10
1
101011
100100110100111100001101000101011100
1011011000011001101101010110000111011001001100110101111100110000100100101010000000110110010001110011101011000001011001000010001011101110110100110010111111000101101010110000101010101011001111100111011001101111011101
101000000111000010111000110000011000...

output:

1
13
955673880
266148454
368723690
496979115
190983211
772121423
932555320
843716403

result: