Submission #316955

#TimeUsernameProblemLanguageResultExecution timeMemory
316955parsabahramiPalindromic Partitions (CEOI17_palindromic)C++17
100 / 100
217 ms26744 KiB
//! Bruh Army #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll, ll> pll; #define sz(x) (ll) x.size() #define all(x) (x).begin(),(x).end() #define F first #define S second ll Pow(ll a, ll b, ll md, ll ans = 1) { for (; b; b >>= 1, a = a * a % md) if (b & 1) ans = ans * a % md; return ans % md; } const ll MAXN = 1e6 + 10; const ll INF = 8e18; const ll MOD = 1e9 + 7;\ const ll base = 31; ll hsh[MAXN], pw[MAXN], n, q; char s[MAXN]; ll get(ll l, ll r) { return (hsh[r] - hsh[l - 1] * pw[r - l + 1] % MOD + MOD) % MOD; } ll memo(ll l, ll r) { if (r < l) return 0; if (l == r) return 1; ll L = l, R = r; for (; L < R; L++, R--) { if (L > R) break; if (get(l, L) == get(R, r)) return memo(L + 1, R - 1) + 2; } return 1; } void solve() { scanf("%s", s + 1); n = strlen(s + 1); hsh[0] = 0; for (ll i = 1; i <= n; i++) { hsh[i] = (hsh[i - 1] * base % MOD + s[i] - 'a' + 1) % MOD; } printf("%lld\n", memo(1, n)); } int main() { pw[0] = 1; for (ll i = 1; i < MAXN; i++) pw[i] = pw[i - 1] * base % MOD; scanf("%lld", &q); while (q--) { solve(); } return 0; }

Compilation message (stderr)

palindromic.cpp: In function 'void solve()':
palindromic.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   43 |  scanf("%s", s + 1);
      |  ~~~~~^~~~~~~~~~~~~
palindromic.cpp: In function 'int main()':
palindromic.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |  scanf("%lld", &q);
      |  ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...