제출 #850868

#제출 시각아이디문제언어결과실행 시간메모리
850868dungzPalindromic Partitions (CEOI17_palindromic)C++17
0 / 100
2 ms348 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll const MOD=1e9+9,base=31;
ll p[1000005];
void sol()
{
    string s;
    cin>>s;
    s=" "+s;
    int i=1,j=s.size()-1;
    ll hash1=0,hash2=0;
    int d=0,ans=0;
    p[0]=1;
    for(int i=1;i<=s.size()-1;i++)
    {
        p[i]=(p[i-1]*base)%MOD;
    }
    int flag=1;
    for(int step=1;step<=s.size()/2-(s.size()%2==0?1:0);step++)
    {
        hash1=(hash1*base+s[i]-'a'+1)%MOD;
        hash2=(hash2+(s[j]-'a'+1)*p[d])%MOD;
        flag=1;
        if(hash1==hash2)
        {
            flag=0;
            hash1=0;
            hash2=0;
            ans+=2;
            d=-1;
        }
        d++;
        i++,j--;
    }
    if(s.size()%2==1) cout<<ans+flag<<endl;
    else cout<<ans+1<<endl;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("task.inp","r",stdin);
        freopen("task.out","w",stdout);
    #endif // ONLINE_JUDGE
    int t;
    cin>>t;
    while(t--)
    {
        sol();
    }
}

컴파일 시 표준 에러 (stderr) 메시지

palindromic.cpp: In function 'void sol()':
palindromic.cpp:16:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for(int i=1;i<=s.size()-1;i++)
      |                 ~^~~~~~~~~~~~
palindromic.cpp:21:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int step=1;step<=s.size()/2-(s.size()%2==0?1:0);step++)
      |                    ~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp: In function 'int main()':
palindromic.cpp:44:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |         freopen("task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
palindromic.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen("task.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...