Submission #249404

# Submission time Handle Problem Language Result Execution time Memory
249404 2020-07-14T21:56:24 Z uacoder123 Palindromic Partitions (CEOI17_palindromic) C++14
100 / 100
750 ms 13100 KB
 #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
 
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
int m=1000000007;
lli cal(lli p,lli n)
{
  lli b=0,ans=1,a=n;
  while((1LL<<b)<=p)
  {
    if(bit(p,b))
      ans=(ans*a)%m;
    a=(a*a)%m;
    b++;
  }
  return(ans);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int test=1;
  cin>>test;
  for(;test>0;--test)
  {
    lli n,p=131,c=0,l=0,la=0,r,ls=0,rs=0;
    string s;
    cin>>s;
    n=s.size();
    r=n-1;
    while(l<=r)
    {
      ls=(ls+((s[l]-'a')*cal(l-la+1,p))%m)%m;
      rs=((rs*p)%m+(lli(s[n-1-la-(l-la)]-'a')*p)%m)%m;
      if(l!=r&&rs==ls)
      {
        r=n-1-la-(l-la)-1;
        rs=0;
        ls=0;
        c+=2;
        la=l+1;
        l=la;
        if(l==r)
          c++;
      }
      else
      {
        r--;
        l++;
        if(l>=r)
          c++;
      }
      if(l>=r)
      {
        break;
      }
    }
    cout<<c<<endl;
  }
  return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 5 ms 512 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 675 ms 13100 KB Output is correct
15 Correct 600 ms 7828 KB Output is correct
16 Correct 750 ms 11988 KB Output is correct
17 Correct 119 ms 6976 KB Output is correct