Submission #209877

#TimeUsernameProblemLanguageResultExecution timeMemory
209877ZwariowanyMarcinSavez (COCI15_savez)C++14
120 / 120
248 ms50236 KiB
#include <bits/stdc++.h> #define LL long long #define LD long double #define pb push_back #define mp make_pair #define ss(x) (int) x.size() #define fi first #define se second #define cat(x) cerr << #x << " = " << x << endl #define rep2(i, j, n) for (LL i = j; i <= n; ++i) #define rep(i, j, n) for (int i = j; i <= n; ++i) #define per(i, j, n) for (int i = n; j <= i; --i) #define boost cin.tie(0);ios_base::sync_with_stdio(0); #define all(x) x.begin(), x.end() using namespace std; const int N = 2e6 + 12; const int MOD1 = 1e9 + 7; const int MOD2 = 1e9 + 9; const int P = 31; int n; vector <string> v; char s[N]; string t; map <pair<int, int>, int> dp; int h1[N]; int h2[N]; int p1[N]; int p2[N]; void prep(string x) { x = '#' + x; int n = ss(x) - 1; rep(i, 1, n) { h1[i] = ((LL) h1[i - 1] * P + (x[i] - 'A' + 1)) % MOD1; h2[i] = ((LL) h2[i - 1] * P + (x[i] - 'A' + 1)) % MOD2; } } pair <int, int> hh(int l, int r) { pair <int, int> x; x.fi = (h1[r] - (LL) h1[l - 1] * p1[r - l + 1] % MOD1 + MOD1) % MOD1; x.se = (h2[r] - (LL) h2[l - 1] * p2[r - l + 1] % MOD2 + MOD2) % MOD2; return x; } int main() { p1[0] = p2[0] = 1; rep(i, 1, N - 1) { p1[i] = (LL) p1[i - 1] * P % MOD1; p2[i] = (LL) p2[i - 1] * P % MOD2; } scanf ("%d", &n); rep(i, 1, n) { scanf ("%s", s + 1); int n = strlen(s + 1); t = ""; rep(j, 1, n) t.pb(s[j]); v.pb(t); } int best = 0; for (auto it : v) { prep(it); int n = ss(it); pair<int, int> ja = hh(1, n); int x = 1; rep(i, 1, n) { if (hh(1, i) == hh(n - i + 1, n)) { x = max(x, 1 + dp[hh(1, i)]); } } dp[ja] = x; best = max(best, dp[ja]); } printf ("%d\n", best); return 0; }

Compilation message (stderr)

savez.cpp: In function 'int main()':
savez.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d", &n);
  ~~~~~~^~~~~~~~~~
savez.cpp:60:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf ("%s", s + 1);
   ~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...