Submission #425176

#TimeUsernameProblemLanguageResultExecution timeMemory
425176cpp219Palindromic Partitions (CEOI17_palindromic)C++14
100 / 100
143 ms28684 KiB
#pragma GCC optimization "O2" #pragma GCC optimization "unroll-loop" #pragma GCC target ("avx2") #include <bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second using namespace std; const ll N = 1e6 + 9; const ll mod = 1e9 + 7; const ll base = 31; typedef pair<ll,ll> LL; string s; ll T,n,Hash[N],fac[N]; ll GetHash(ll i,ll j){ return (Hash[j] - Hash[i - 1]*fac[j - i + 1] + mod*mod)%mod; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0); #define task "tst" if (fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); //freopen(task".out", "w", stdout); } fac[0] = 1; for (ll i = 1;i < N;i++) fac[i] = (fac[i - 1]*base)%mod; cin>>T; while(T--){ cin>>s; n = s.size(); s = " " + s; for (ll i = 1;i <= n;i++) Hash[i] = (Hash[i - 1]*base + s[i] - 'a' + 1)%mod; ll ans = 0; ll L = 1,R = n; while(L <= R){ ll chosen = mod; for (ll len = 1;len <= R - L + 1;len++){ ll p = GetHash(L,L + len - 1),q = GetHash(R - len + 1,R); //cout<<len<<" "<<p<<" "<<q<<"\n"; if (p == q){ chosen = len; break; } } ans++; if (chosen != R - L + 1) ans++; //cout<<chosen; return 0; L = L + chosen; R = R - chosen; } cout<<ans<<"\n"; } }

Compilation message (stderr)

palindromic.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
palindromic.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
palindromic.cpp: In function 'int main()':
palindromic.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...