답안 #1096976

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1096976 2024-10-05T15:31:48 Z moiaaaaaaa Palindromic Partitions (CEOI17_palindromic) C++14
0 / 100
0 ms 348 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7,moi=1e6+111,base=311,mod1=1e9+7,base1=331;
string s,t;
int n,m;
bool check;
ll Pow[moi],Hash[moi],kmp[moi];
ll gethash(int i,int j)
{
    return (Hash[j]-Hash[i-1]*Pow[j-i+1]%mod+mod)%mod;
}
void Input()
{
 cin>>m;
 while(m--)
 {
 cin>>s;
 int res=0;
   while(1)
   {
    n=s.size();
    s=" "+s;
    int k=kmp[1]=0;
   for(int i=2;i<=n;i++)
   {
    while(k>0&&s[i]!=s[k+1]){k=kmp[k];}
    if(s[i]==s[k+1])kmp[i]=++k;
    else kmp[i]=0;
   }
     k=kmp[n];
     if(k==0){res++;cout<<res<<'\n';break;}
     while(kmp[k]>0){k=kmp[k];}
      s.erase(n-k+1,k);
      s.erase(0,k+1);
      res+=2;
   }
 }
}
int main()
{
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
 cout.tie(NULL);
 if(fopen("a.inp","r"))
 {
 freopen("a.inp","r",stdin);
 freopen("a.out","w",stdout);
 }
 Input();
}

Compilation message

palindromic.cpp: In function 'int main()':
palindromic.cpp:47:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  freopen("a.inp","r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~
palindromic.cpp:48:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  freopen("a.out","w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -