답안 #853323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853323 2023-09-24T06:28:02 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 ;
      lcp[i] = 0;
      dp[i] = 1;
      for(int j = i+1 ; j <= n/2 ; j++){
        while(k!=0 && s[i+k] != s[j]){
          k = lcp[i+k-1] ; 
        }
        if(s[i+k] == s[j])k++;
        lcp[j]= k ;
      }
      k =0  ;
      for(int j = n+1 - n/2 ; j <= n-i+1 ; j++){
        while(k!=0 && s[j] != s[i+k]){
          k = lcp[i+k-1] ;
        }
        if(s[i+k] == s[j])k++;
        lcp[j] = k ;
      }
      k = lcp[n-i+1] ;
      while(k!=0){
        dp[i] = max(dp[i] , dp[i+k] + 2) ;
        k = lcp[k+i-1];
      }
      
    }
    cout << dp[1] << "\n"; 
  }
}
/*

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -