QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#205254#7512. Almost Prefix ConcatenationsupepapupuWA 2ms16152kbC++172.5kb2023-10-07 15:18:462023-10-07 15:18:46

Judging History

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

  • [2023-10-07 15:18:46]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:16152kb
  • [2023-10-07 15:18:46]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 1e6 + 10, mod = 998244353, base = 149;

ll qmi(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

ll inv(ll a) { return qmi(a, mod - 2); }

void inc(ll &a, ll b) {
    a += b;
    if (a >= mod) a -= mod;
}

void dec(ll &a, ll b) {
    a -= b;
    if (a < 0) a += mod;
}

ll add(ll a, ll b) {
    a += b;
    return a < mod ? a : a - mod;
}

ll del(ll a, ll b) {
    a -= b;
    return a >= 0 ? a : a + mod;
}

ll cnt[N], sum[N];
ll dcnt[N], dsum[N];
char s[N], t[N];
ll hss[N], hst[N], p[N];
ll R[N], ways[N];

ll get(int l, int r, ll hs[]) {
    ll len = p[r - l + 1];
    return del(hs[r], hs[l - 1] * len % mod);
}

int main() {
    scanf("%s%s", s + 1, t + 1);
    cnt[1] = sum[1] = 1;
    int n = strlen(s + 1), m = strlen(t + 1);
    p[0] = 1;
    for (int i = 1; i <= max(n, m); ++i) p[i] = p[i - 1] * base % mod;
    for (int i = 1; i <= n; ++i) hss[i] = add(hss[i - 1] * base % mod, s[i]);
    for (int i = 1; i <= m; ++i) hst[i] = add(hst[i - 1] * base % mod, t[i]);
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        dcnt[i] += dcnt[i - 1], dsum[i] += dsum[i - 1];
        cnt[i] += dcnt[i], sum[i] += dsum[i];
        // inc(ans, sum[i]);
        int l = i - 1, r = min(n, i + m - 1), mid;
        while (l < r) {
            mid = l + r + 1 >> 1;
            if (get(i, mid, hss) == get(1, mid - i + 1, hst)) l = mid;
            else r = mid - 1;
        }
        l += 2;
        int ll = l - 1, rr = min(n, i + m - 1);
        while (ll < rr) {
            mid = ll + rr + 1 >> 1;
            if (get(l, mid, hss) == get(l - i + 1, mid - i + 1, hst)) ll = mid;
            else rr = mid - 1;
        }
        // cout << i << ' ' << rr << ' ' << sum[i] << el;
        R[i] = rr + 1;
        // cout << ans << el;
        // if (rr == n) inc(ans, sum[i]);
        inc(dcnt[i + 1], cnt[i]), inc(dsum[i + 1], add(sum[i] % mod, cnt[i] * 2 % mod));
        dec(dcnt[rr + 2], cnt[i]), dec(dsum[rr + 2], add(sum[i] % mod, cnt[i] * 2 % mod));
    }
    ways[n + 1] = 1;
    for (int i = n; i; --i) {
        ways[i] = del(ways[i + 1], ways[R[i] + 1]);
        // cout << ways[i] << el;
        inc(ans, ways[i] * sum[i] % mod);
        inc(ways[i], ways[i + 1]);
    }
    printf("%lld\n", ans);
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 13940kb

input:

ababaab
aba

output:

473

result:

ok 1 number(s): "473"

Test #2:

score: 0
Accepted
time: 2ms
memory: 13852kb

input:

ac
ccpc

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 16152kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq...

output:

146222291

result:

wrong answer 1st numbers differ - expected: '75038697', found: '146222291'