Submission #393348

# Submission time Handle Problem Language Result Execution time Memory
393348 2021-04-23T08:49:39 Z rumen_m Palindromic Partitions (CEOI17_palindromic) C++17
100 / 100
159 ms 28508 KB
# include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
const long long base = 27;
const long long maxn = 1e6+5;
long long hashes[maxn];
long long poww[maxn];
long long find_hash(long long from, long long to)
{
    long long pref = (hashes[from-1]*poww[to-from+1])%MOD;
    long long ans = (hashes[to]+MOD-pref)%MOD;
    return ans;
}
void solve()
{
    string s;
    cin>>s;
    long long ans = 0;
    poww[0] = 1;
    hashes[0] = 0;
    long long i;
    for(i = 1; i<=s.size();i++)
    {
        long long ch = s[i-1]-'a'+1;
        poww[i] = (poww[i-1]*base)%MOD;
        hashes[i] = (hashes[i-1]*base + ch)%MOD;
    }
    long long prev = 1;
    long long from = 1;
    long long last = s.size();
    long long endd = s.size();
    bool fl = false;
    while(from<last)
    {
        if(find_hash(prev,from)==find_hash(last,endd))
        {
            fl = false;
            ans+=2;
           // cout<<"  "<<from<<endl;
            prev = from+1;
            endd = last-1;
            from++;
            last--;
            continue;
        }
        fl = true;
        from++;
        last--;
    }
    if(fl||from==last)ans++;
    cout<<ans<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    long long t;
    cin>>t;
    while(t--)
        solve();
}

Compilation message

palindromic.cpp: In function 'void solve()':
palindromic.cpp:22:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(i = 1; i<=s.size();i++)
      |                ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 2 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 2 ms 588 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 2 ms 464 KB Output is correct
14 Correct 159 ms 28508 KB Output is correct
15 Correct 91 ms 23380 KB Output is correct
16 Correct 155 ms 27412 KB Output is correct
17 Correct 86 ms 15168 KB Output is correct