QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#402145#7416. Grammarlyjames1BadCreeperWA 4ms6160kbC++141.4kb2024-04-30 00:15:312024-04-30 00:15:32

Judging History

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

  • [2024-04-30 00:15:32]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:6160kb
  • [2024-04-30 00:15:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int P = 998244353; 
const int N = 3e5 + 5; 

inline int poww(int a, int b) {
    int r = 1; 
    for (; b; b >>= 1, a = 1ll * a * a % P) if (b & 1) r = 1ll * r * a % P; 
    return r; 
}

int n, fac[N], ifac[N]; 
char a[N]; 

inline void initFac(void) {
    for (int i = fac[0] = 1; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % P; 
    ifac[N - 1] = poww(fac[N - 1], P - 2); 
    for (int i = N - 2; i >= 0; --i) ifac[i] = 1ll * ifac[i + 1] * (i + 1) % P; 
}
inline int C(int n, int m) {
    if (n < m || n < 0 || m < 0) return 0; 
    return 1ll * fac[n] * ifac[m] % P * ifac[n - m] % P; 
}

int main(void) {
    initFac(); 
    ios::sync_with_stdio(0); 
    cin >> a + 1; n = strlen(a + 1); 
    int ans = poww(2, n) - 1; 
    for (int l = 1, r; l <= n; l = r + 1) {
        r = l; 
        while (r < n && a[r + 1] == a[l]) ++r; 
        int t = r - l + 1; 
        if (t > 1) ans = (ans - 1ll * C(n - t, l - 1) * (poww(2, t) - 1 - t)) % P; 
        for (int i = l + 1; i < r; ++i) {
            int t = i - l + 1; 
            ans = (ans - 1ll * C(n - t - 1, l - 2) * (poww(2, t) - 1 - t)) % P; 

            t = r - i + 1; 
            ans = (ans - 1ll * C(n - t - 1, n - r - 1) * (poww(2, t) - 1 - t)) % P; 
        }
        // cerr << l << " " << r << "\n"; 
    }
    cout << ans << "\n"; 
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 6056kb

input:

abba

output:

13

result:

ok 1 number(s): "13"

Test #2:

score: 0
Accepted
time: 4ms
memory: 5964kb

input:

benbeipo

output:

255

result:

ok 1 number(s): "255"

Test #3:

score: 0
Accepted
time: 4ms
memory: 5928kb

input:

iqiiiiiiqq

output:

300

result:

ok 1 number(s): "300"

Test #4:

score: 0
Accepted
time: 4ms
memory: 5928kb

input:

aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

output:

35

result:

ok 1 number(s): "35"

Test #5:

score: 0
Accepted
time: 0ms
memory: 6060kb

input:

u

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 4ms
memory: 5964kb

input:

yy

output:

2

result:

ok 1 number(s): "2"

Test #7:

score: 0
Accepted
time: 3ms
memory: 5952kb

input:

bg

output:

3

result:

ok 1 number(s): "3"

Test #8:

score: 0
Accepted
time: 3ms
memory: 6160kb

input:

qqq

output:

3

result:

ok 1 number(s): "3"

Test #9:

score: 0
Accepted
time: 0ms
memory: 6036kb

input:

yyh

output:

6

result:

ok 1 number(s): "6"

Test #10:

score: 0
Accepted
time: 4ms
memory: 5928kb

input:

cccc

output:

4

result:

ok 1 number(s): "4"

Test #11:

score: 0
Accepted
time: 4ms
memory: 6032kb

input:

kknn

output:

13

result:

ok 1 number(s): "13"

Test #12:

score: 0
Accepted
time: 4ms
memory: 5964kb

input:

ttttt

output:

5

result:

ok 1 number(s): "5"

Test #13:

score: 0
Accepted
time: 4ms
memory: 6000kb

input:

aaaba

output:

25

result:

ok 1 number(s): "25"

Test #14:

score: -100
Wrong Answer
time: 4ms
memory: 5928kb

input:

kktkktktkktttktkttktttkttkttkt

output:

-24059340

result:

wrong answer 1st numbers differ - expected: '974185013', found: '-24059340'