QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#217696#793. Palindromic Partitions_LAP_100 ✓87ms12388kbC++141.2kb2023-10-17 10:19:562023-10-17 10:19:58

Judging History

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

  • [2023-10-17 10:19:58]
  • 评测
  • 测评结果:100
  • 用时:87ms
  • 内存:12388kb
  • [2023-10-17 10:19:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10, BASE = 13331, MOD = 1e9 + 7;
inline int Plus(int a, int b) {return a + b >= MOD ? a + b - MOD : a + b; }
inline int Minus(int a, int b) {return a - b < 0 ? a - b + MOD : a - b; }
int n, Hash[N], base[N]; char s[N];

inline int calc(int l, int r) {
    return Minus(Hash[r], 1ll * Hash[l - 1] * base[r - l + 1] % MOD);
}
inline void solve() {
    cin >> (s + 1); n = strlen(s + 1);
    Hash[0] = 0;
    for(int i = 1; i <= n; i ++)
        Hash[i] = Plus(1ll * Hash[i - 1] * BASE % MOD, s[i]);
    int res = 0;
    for(int i = 1, j = n, len = 1; ; ) {
        if(i > j) break;
        if(i + len - 1 >= j - len + 1) {res ++; break; }
        if(calc(i, i + len - 1) == calc(j - len + 1, j)) {
            res += 2, i += len, j -= len, len = 1;
            continue;
        } else {
            len ++; continue;
        }
    }
    cout << res << '\n';
}

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

    base[0] = 1;
    for(int i = 1; i <= 1000000; i ++)
        base[i] = 1ll * base[i - 1] * BASE % MOD;

    int T; cin >> T;
    while(T --) solve();

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 15
Accepted

Test #1:

score: 15
Accepted
time: 6ms
memory: 7572kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaabaaaaaaaaaaaaaab
aaaaaaaaaaaaabxaaaaaaaaaaaaab
baaaaaaaaaaaaaabaaaaaaaaaaaaaa
aabbaabbaabbaaaaaaaabbaabbaabb
ababababababababababababababab
abcabcabcabcabcabcabcabcabcabc
abcabcabcabcabccbacbacbacbacba
qntshryhcojkqnlmqeob...

output:

30
29
2
3
2
12
15
10
30
3

result:

ok 10 lines

Test #2:

score: 0
Accepted
time: 6ms
memory: 9708kb

input:

10
aaabbbbaabbbbbbbaaaaabbb
aaaababbbaabbabbbaaaaababbb
aaabbbbaaaaaaaabbbba
aaaaaaabbbbbbbaaaaaaabbbbbbb
babbababbabbababbabab
abbabaabbaababba
bonobo
palindrome
deemed
level

output:

10
5
10
2
17
16
3
1
5
5

result:

ok 10 lines

Test #3:

score: 0
Accepted
time: 6ms
memory: 9584kb

input:

5
abba
aabaab
x
aa
ab

output:

4
2
1
2
1

result:

ok 5 lines

Test #4:

score: 0
Accepted
time: 6ms
memory: 8024kb

input:

10
aabbaabbaabbaaaaaaaabbaabbaabb
aabbaabbaabbaaaaabbaabbaabb
aabbaabbaabbaaaaabbaabbaabb
aabbaabbaabbaaaaaaaabbaabbaabb
aabbaabbaabbaaaaaaaabbaabbaabb
aabbaabbaabbaaaaabbaabbaabb
aabbaabbaabbaaaaaaaabbaabbaabb
aabbaabbaabbaaaaaabbaabbaabb
aabbaabbaabbaaaaaaabbaabbaabb
aabbaabbaabbaaaaaaabbaabbaabb

output:

12
9
9
12
12
9
12
10
11
11

result:

ok 10 lines

Test #5:

score: 0
Accepted
time: 6ms
memory: 8560kb

input:

10
abbabaabbaababba
abbabaabbaababba
abbabaabbaababba
abbabaabbaababba
abbabaabbaababba
abbabaabbaababba
abbabaabbaababba
abbabaabbaababba
abbabaabbaababba
abbabaabbaababba

output:

16
16
16
16
16
16
16
16
16
16

result:

ok 10 lines

Subtask #2:

score: 20
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 20
Accepted
time: 6ms
memory: 8280kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

300
299
2
3
2
30
150
100
300
11

result:

ok 10 lines

Test #7:

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

input:

6
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbabbbbababaaabbababbbaabbabbabbaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaababbbababbababbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbabbbbababaaabbababbbaabbabbabbaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
aaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

3
9
7
2
177
256

result:

ok 6 lines

Test #8:

score: 0
Accepted
time: 5ms
memory: 7532kb

input:

10
aaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbbaaaaaaaabbbbbbbb
aaaaaaaab...

output:

47
32
31
33
22
46
46
24
34
46

result:

ok 10 lines

Test #9:

score: 0
Accepted
time: 6ms
memory: 8376kb

input:

10
abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababba
abbabaabbaababbabaababbaabbabaabbaababba...

output:

256
256
256
256
256
256
256
256
256
256

result:

ok 10 lines

Subtask #3:

score: 25
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Test #10:

score: 25
Accepted
time: 3ms
memory: 7508kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

10000
9999
2
3
2
100
5000
3333
9996
495

result:

ok 10 lines

Test #11:

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

input:

6
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

3
9
18
2
5169
4096

result:

ok 6 lines

Test #12:

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

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaa...

output:

258
282
116
109
287
192
167
251
148
146

result:

ok 10 lines

Test #13:

score: 0
Accepted
time: 6ms
memory: 9756kb

input:

10
abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabb...

output:

4096
4096
4096
4096
4096
4096
4096
4096
4096
4096

result:

ok 10 lines

Subtask #4:

score: 40
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #14:

score: 40
Accepted
time: 87ms
memory: 12356kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1000000
999999
2
3
2
1000
500000
333333
999996
48937

result:

ok 10 lines

Test #15:

score: 0
Accepted
time: 44ms
memory: 12388kb

input:

6
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

3
3
7
2
635623
262144

result:

ok 6 lines

Test #16:

score: 0
Accepted
time: 87ms
memory: 12284kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1777
1925
1110
1151
2733
2540
2190
2760
1152
2229

result:

ok 10 lines

Test #17:

score: 0
Accepted
time: 47ms
memory: 12080kb

input:

10
abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabb...

output:

262144
262144
262144
262144
262144
262144
262144
262144
262144
262144

result:

ok 10 lines