QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#560#348188#8330. Count off 3hos_lyricucup-team1198Failed.2024-03-10 15:26:112024-03-10 15:26:12

詳細信息

Extra Test:

Accepted
time: 1733ms
memory: 6500kb

input:

10
111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111011111111111111111111111111111111111111111111111111111111...

output:

954700341
358216478
803662031
502416034
405170373
202420697
862652329
484755287
259469240
790231310

result:

ok 10 numbers

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#348188#8330. Count off 3ucup-team1198#AC ✓1840ms6716kbC++202.8kb2024-03-09 17:23:402024-10-13 18:46:00

answer

#include <map>
#include <set>
#include <array>
#include <cmath>
#include <deque>
#include <bitset>
#include <random>
#include <string>
#include <vector>
#include <cassert>
#include <complex>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <cstring>

#define ll long long

using namespace std;

int go(int state, int by) {
    int n_state = 0;

    int pw = 1;
    for (int i = 1; i < 7; ++i) {
        int cur = state % 7;
        state /= 7;
        n_state += pw * ((cur * i + by) % 7);
        pw *= 7;
    }

    return n_state;
}

bool good(int state) {
    for (int i = 1; i < 7; ++i) {
        if (state % 7 == 0) return 0;
        state /= 7;
    }
    return 1;
}

const int ST = 7 * 7 * 7 * 7 * 7 * 7;

int ago[2][ST];

// 117649

ll count_good[2][ST];

const int MOD = 1e9 + 7;

void back(const int i) {
    static int counter = 0;

    // from i to i - 1;
    memset(count_good[1-i], 0, sizeof(count_good[1-i]));

    for (int j = 0; j < ST; ++j) {
        count_good[1-i][ago[0][j]] += count_good[i][j];
        count_good[1-i][ago[1][j]] += count_good[i][j];
    }

    counter++;

    if (counter == 33) {
        for (int j = 0; j < ST; ++j) {
            count_good[1-i][j] %= MOD;
        }

        counter = 0;
    }

    // maybe %;
}

void solve() {
    for (int i = 0; i < ST; ++i) {
        ago[0][go(i, 0)] = i;
        ago[1][go(i, 1)] = i;
    }

    int t;
    cin >> t;
    vector<string> s(t);

    for (int i = 0; i < t; ++i) {
        cin >> s[i];

        // s[i] = '1';
        // for (int j = 0; j < 9999; ++j) {
        //     s[i] += '0' + rand() % 2;
        // }
    }

    vector<ll> ans(t, 0);

    vector<vector<int>> query(t);
    for (int i = 0; i < t; ++i) {
        query[i].resize(s[i].size());
        int st = 0;
        for (int j = 0; j < s[i].size(); ++j) {
            if (s[i][j] == '1') {
                query[i][s[i].size() - 1 - j] = go(st, 0);
                st = go(st, 1);
            } else {
                query[i][s[i].size() - 1 - j] = -1;
                st = go(st, 0);
            }
        }

        ans[i] += (good(st) && s[i].back() == '1');
    }

    for (int i = 0; i < ST; ++i) {
        count_good[1][i] = good(go(i, 1));
    }

    // back(1);

    for (int i = 1; i < 10001; ++i) {
        for (int j = 0; j < t; ++j) {
            if (i < query[j].size() && query[j][i] != -1) {
                ans[j] = (ans[j] + count_good[i % 2][query[j][i]]) % MOD;
            }
        }
        back(i % 2);
    }

    for (int i = 0; i < t; ++i) {
        cout << ans[i] << '\n';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    solve();
    
    return 0;
}