답안 #916707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
916707 2024-01-26T10:23:33 Z vjudge1 Palindromic Partitions (CEOI17_palindromic) C++17
60 / 100
7 ms 1372 KB
#include <bits/stdc++.h>

using namespace std;

int longpal_partitions(char *word)
{
    const int n=strlen(word);
    const int prime=131;

    int countedch=0;
    int piececounts=0;

    while(countedch*2<n)
    {
        int lhash=0,rhash=0,power=1;

        for(int piecesize=1;true;piecesize++)
        {
            int l=countedch,r=n-countedch-piecesize;
            if(l+piecesize-1>=r)
                return piececounts+1;
            if(piecesize==1)
                power=1;
            else
                power*=prime;
            lhash+=static_cast<int>(word[l+piecesize-1])*power;
            rhash=static_cast<int>(word[r])+rhash*prime;
            if(lhash==rhash && strncmp(word+l,word+r,piecesize)==0)
            {
                piececounts+=2;
                countedch+=piecesize;
                break;
            }
        }
    }
    return piececounts;
}

int main()
{
    int n;
    char word[510000];
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>word;
        assert(strlen(word)<=510000);
        cout<<longpal_partitions(word)<<endl;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 932 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 932 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 932 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 2 ms 856 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 860 KB Output is correct
2 Correct 1 ms 932 KB Output is correct
3 Correct 1 ms 860 KB Output is correct
4 Correct 1 ms 860 KB Output is correct
5 Correct 1 ms 856 KB Output is correct
6 Correct 1 ms 860 KB Output is correct
7 Correct 1 ms 860 KB Output is correct
8 Correct 1 ms 1112 KB Output is correct
9 Correct 0 ms 860 KB Output is correct
10 Correct 2 ms 856 KB Output is correct
11 Correct 1 ms 860 KB Output is correct
12 Correct 2 ms 860 KB Output is correct
13 Correct 3 ms 860 KB Output is correct
14 Runtime error 7 ms 1372 KB Execution killed with signal 11
15 Halted 0 ms 0 KB -