답안 #853324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853324 2023-09-24T06:42:05 Z manizare Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
1 ms 348 KB
#include <bits/stdc++.h> 

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define Pii pair< pii , pii >
#define ll long long

using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 10002 + 10 , maxq = 1e7 + 1 ,  inf = 1e8 + 10 , mod= 998244353 ,lg = 20 ;
int lcp[maxn] ,dp[maxn]  ;  
signed main(){
  ios::sync_with_stdio(false); cin.tie(0) ;
  int t; 
  cin >> t ;
  while(t--){
    string s ;
    cin >> s ;
    int n = (int)s.size() ;
    s = " " + s; 
    if(n%2==1)dp[n/2+1] = 1 ;
    for(int i = n/2 ; i >= 1 ; i--){
      int k =0 ;
      dp[i] = 1;
      string a , b; 
      for(int j = i ; j <= n/2 ; j++){
        a += s[j] ;
      }
      for(int j = n+1 - n/2;  j<= n-i+1 ; j++){
        b += s[j] ;
      }
      lcp[0] = 0 ;
      for(int j = 1 ; j < a.size() ; j++){
        while(k!=0 && a[k] != a[j]){
          k = lcp[k-1] ; 
        }
        if(a[k] == a[j])k++;
        lcp[j]= k ;
      }
      k =0  ;
      int f ; 
      for(int j = 0 ; j < b.size() ; j++){
        while(k!=0 && b[j] != a[k]){
          k = lcp[k-1] ;
        }
        if(b[j] == a[k])k++;
        f = k ;
      }
      while(f!=0){
        dp[i] = max(dp[i] , dp[i+f] + 2) ;
        f = lcp[f-1];
      }
      
    }
    cout << dp[1] << "\n"; 
  }
}
/*

*/

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:38:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |       for(int j = 1 ; j < a.size() ; j++){
      |                       ~~^~~~~~~~~~
palindromic.cpp:47:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |       for(int j = 0 ; j < b.size() ; j++){
      |                       ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -