QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#103962#4375. StringzbceyondTL 0ms0kbC++201.7kb2023-05-08 00:55:292023-05-08 00:55:32

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-08 00:55:32]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-05-08 00:55:29]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;i++)
using namespace std;
#define int long long
const int N = 2e5+10;
const int mod = 998244353;
int qmi(int a,int b) {
    int res = 1;
    for (; b; b >>= 1, a = a * a % mod) {
        if (b & 1)res = res * a % mod;
    }
    return res;
}
void solve(int tc) {
    string s;
    int k;
    cin >> s >> k;
    s = " " + s;
    int n = s.size();
    vector<int> nxt(n);
    vector<vector<int>> e(n);
    e[0].push_back(1);
    for (int i = 2,j=0; i < n; i++) {
//        nxt[i] = nxt[i - 1];
//        while (nxt[i] and s[i] != s[nxt[i] + 1]){
//            nxt[i] = nxt[nxt[i]];
//        }
//        if (s[i] == s[nxt[i] + 1])nxt[i]++;
//        e[nxt[i]].push_back(i);
        while (j and s[j + 1] != s[i])j = nxt[j];
        if (s[j + 1] == s[i])j++;
        nxt[i] = j;
        e[j].push_back(i);
    }
    vector<int> cnt(k);
    int ans = 1;
    deque<int> q;
    vector<int>tmp;
    function<void(int, int)> dfs = [&](int u, int fa) {
        while (q.size() and q.front() * 2 <= u)cnt[q.front() * 2 % k]--, tmp.push_back(q.front()), q.pop_front();

        int x = cnt[u % k] + 1;
        if (u % k == 0 and u != 0)x++;
        ans = ans * x % mod;

        cnt[u * 2 % k]++, q.push_back(u);

        for (auto &v: e[u]) {
            dfs(v, u);
        }

        while (tmp.size())cnt[tmp.back() * 2 % k]++, q.push_front(tmp.back()), tmp.pop_back();
        cnt[u * 2 % k]--;
        q.pop_back();
    };
    dfs(0, -1);
    cout << ans;
}
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc = 1;
    cin >> tc;
    for (int i = 1; i <= tc; i++) {
        solve(i);
    }
}

详细

Test #1:

score: 0
Time Limit Exceeded

input:

10
kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk...

output:


result: