답안 #619708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
619708 2022-08-02T14:51:17 Z socpite Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
438 ms 22740 KB
#include<bits/stdc++.h>
using namespace std;

#define f first
#define s second

typedef long long ll;

const int maxn = 1e6+5;
const int mod = 1e9+7;

int t, n, q;

string str, str2;

int d[2*maxn];
int man1[maxn], man2[maxn];

void pp(){
    string tmp;
    for(int i = n-1; i >= n/2 + (n&1); i--)tmp+=str[i];
    str2 = tmp;
    tmp = "";
    for(int i = 0; i < n/2; i++)tmp+=str[i];
    str = tmp;
    tmp = "$#";
    for(int i = 0; i < n/2; i++){
        tmp+=str[i];
        tmp+='#';
    }
    tmp+='^';
    str = tmp;
    tmp = "$#";
    for(int i = n/2+(n&1); i < n; i++){
        tmp+=str2[i-(n/2+(n&1))];
        tmp+='#';
    }
    tmp += '^';
    str2 = tmp;
    //cout << str << " " << str2 << endl;
}

int main(){
    cin >> t;
    while(t--){
        cin >> str;
        n=str.size();
        pp();
        for(int i = 1, l =0,r = 0; i < str.size(); i++){
            if(r < i)d[i]=0;
            else d[i] = min(r-i, d[l+r-i]);
            while(str[i+d[i]] == str2[i-d[i]] && str[i-d[i]] == str2[i+d[i]])d[i]++;
            if(i+d[i] > r){
                l = i-d[i], r = i+d[i];
            }
            if(i&1){
                if(i > 1 && i < str.size()-2)man2[(i>>1)-1]=d[i]>>1;
            }
            else{
                if(i && i < str.size()-1)man1[(i>>1)-1]=d[i]>>1;
            }
        }
        int crr = 0, ans = 0;
        for(int i = 0; i < n/2; i++){
            if(man1[i]){
                if(crr >= i-man1[i]+1 && crr <= i){
                    crr+=(i-crr)*2+1;
                    ans+=2;
                }
            }
            //cout << man1[i] << endl;
            if(man2[i] && i < n/2-1){
                if(crr >= i-man2[i]+1 && crr <= i){
                    crr+=(i-crr+1)*2;
                    ans+=2;
                }
            }
            //cout << man2[i] << endl;
        }
        if(crr < n/2 || (n&1))ans++;
        cout << ans << "\n";
    }

}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:49:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |         for(int i = 1, l =0,r = 0; i < str.size(); i++){
      |                                    ~~^~~~~~~~~~~~
palindromic.cpp:57:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |                 if(i > 1 && i < str.size()-2)man2[(i>>1)-1]=d[i]>>1;
      |                             ~~^~~~~~~~~~~~~~
palindromic.cpp:60:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |                 if(i && i < str.size()-1)man1[(i>>1)-1]=d[i]>>1;
      |                         ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 6 ms 468 KB Output is correct
11 Correct 4 ms 540 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 6 ms 468 KB Output is correct
11 Correct 4 ms 540 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 516 KB Output is correct
14 Correct 438 ms 22740 KB Output is correct
15 Correct 246 ms 17100 KB Output is correct
16 Correct 397 ms 21204 KB Output is correct
17 Correct 225 ms 12056 KB Output is correct