QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242890#793. Palindromic PartitionsCamillus#60 3ms3844kbC++17930b2023-11-07 18:09:342024-07-04 02:23:06

Judging History

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

  • [2024-07-04 02:23:06]
  • 评测
  • 测评结果:60
  • 用时:3ms
  • 内存:3844kb
  • [2023-11-07 18:09:34]
  • 提交

answer

#include "bits/stdc++.h"

using ll = long long;
using namespace std;

void solve() {
    string s;
    cin >> s;

    int n = (int)s.size();

    int l = 0, r = n - 1;

    int ans = 0;

    while (l <= r) {
        bool ok = false;

        for (int k = 1; k < r - l + 1; k++) {
            if (l + k - 1 < r - k + 1 && s.substr(l, k) == s.substr(r - k + 1, k)) {
                l += k;
                r -= k;
                ans += 2;
                ok = true;
                break;
            }
        }

        if (!ok) {
            ans += 1;
            break;
        }
    }

    cout << ans << '\n';
}

signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    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: 0ms
memory: 3548kb

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: 0ms
memory: 3604kb

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: 0ms
memory: 3540kb

input:

5
abba
aabaab
x
aa
ab

output:

4
2
1
2
1

result:

ok 5 lines

Test #4:

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

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: 0ms
memory: 3604kb

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: 0ms
memory: 3604kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

300
299
2
3
2
30
150
100
300
11

result:

ok 10 lines

Test #7:

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

input:

6
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbabbbbababaaabbababbbaabbabbabbaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaababbbababbababbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbabbbbababaaabbababbbaabbabbabbaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
aaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

3
9
7
2
177
256

result:

ok 6 lines

Test #8:

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

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: 0ms
memory: 3772kb

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: 3704kb

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

10000
9999
2
3
2
100
5000
3333
9996
495

result:

ok 10 lines

Test #11:

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

input:

6
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

3
9
18
2
5169
4096

result:

ok 6 lines

Test #12:

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

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbaaaaaaaaaaaaaaa...

output:

258
282
116
109
287
192
167
251
148
146

result:

ok 10 lines

Test #13:

score: 0
Accepted
time: 1ms
memory: 3672kb

input:

10
abbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbaabbabaabbaababbabaababbaabbabaababbabaabbaababbabaababbaabbabaabbaababbaabbabaababbabaabbaababbabaababbaabbabaababbabaabbaababbaabbabaabb...

output:

4096
4096
4096
4096
4096
4096
4096
4096
4096
4096

result:

ok 10 lines

Subtask #4:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #14:

score: 0
Time Limit Exceeded

input:

10
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:


result: