Submission #1096976

#TimeUsernameProblemLanguageResultExecution timeMemory
1096976moiaaaaaaaPalindromic Partitions (CEOI17_palindromic)C++14
0 / 100
0 ms348 KiB
#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 (stderr)

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);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...