QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#217694#793. Palindromic Partitions_LAP_0 6ms9696kbC++141.1kb2023-10-17 10:19:022023-10-17 10:19:04

Judging History

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

  • [2023-10-17 10:19:04]
  • 评测
  • 测评结果:0
  • 用时:6ms
  • 内存:9696kb
  • [2023-10-17 10:19:02]
  • 提交

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 + 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;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 6ms
memory: 9696kb

input:

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

output:

31
29
3
3
3
13
15
11
31
3

result:

wrong answer 1st lines differ - expected: '30', found: '31'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

0%