Submission #695344

#TimeUsernameProblemLanguageResultExecution timeMemory
695344Nhoksocqt1Savez (COCI15_savez)C++17
120 / 120
164 ms64832 KiB
#include<bits/stdc++.h> using namespace std; #define inf 0x3f3f3f3f #pragma GCC target ("avx2") #pragma GCC optimization ("O3") #pragma GCC optimization ("unroll-loops") #define fi first #define se second typedef long long ll; typedef pair<int, int> ii; template<class X, class Y> inline bool maximize(X &x, const Y &y) {return (x < y ? x = y, 1 : 0);} template<class X, class Y> inline bool minimize(X &x, const Y &y) {return (x > y ? x = y, 1 : 0);} mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int Random(int l, int r) { return uniform_int_distribution<int>(l, r)(rng); } const int NMOD = 2; const int MAXN = 2000006; const int MOD[] = {int(1e9) + 2277, int(1e9) + 5277, int(1e9) + 8277, int(1e9) + 9277}; const int BASE = 256; ll pw[NMOD][MAXN]; struct Hash { ll value[NMOD]; Hash(char c = 0) { for (int i = 0; i < NMOD; ++i) value[i] = c; } Hash operator + (const Hash &h) const { Hash res; for (int i = 0; i < NMOD; ++i) { res.value[i] = value[i] + h.value[i]; if(res.value[i] >= MOD[i]) res.value[i] -= MOD[i]; } return res; } Hash operator - (const Hash &h) const { Hash res; for (int i = 0; i < NMOD; ++i) { res.value[i] = value[i] - h.value[i]; if(res.value[i] < 0) res.value[i] += MOD[i]; } return res; } Hash operator * (int k) const { Hash res; for (int i = 0; i < NMOD; ++i) res.value[i] = value[i] * pw[i][k] % MOD[i]; return res; } bool operator == (const Hash &h) const { Hash res; for (int i = 0; i < NMOD; ++i) { if(value[i] != h.value[i]) return false; } return true; } } h[MAXN]; struct HashPair { ll operator() (const Hash &h) const { return h.value[0] * MOD[1] + h.value[1]; } }; inline Hash getHash(int l, int r) { return (h[r] - h[l - 1]) * (MAXN - r); } unordered_map<Hash, int, HashPair> dp; int numString; void init(void) { for (int i = 0; i < NMOD; ++i) { pw[i][0] = 1; for (int j = 1; j < MAXN; ++j) pw[i][j] = pw[i][j - 1] * BASE % MOD[i]; } } void process() { cin >> numString; init(); int res(0); for (int i = 1; i <= numString; ++i) { string str; cin >> str; int strLen(str.size()); for (int j = 1; j <= strLen; ++j) { h[j] = h[j - 1] + Hash(str[j - 1]) * j; } int dpm(0); for (int j = 1; j <= strLen; ++j) { if(getHash(1, j) == getHash(strLen - j + 1, strLen)) dpm = max(dpm, dp[getHash(1, j)]); } dp[getHash(1, strLen)] = 1 + dpm; res = max(res, 1 + dpm); } cout << res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("savez.inp", "r", stdin); // freopen("savez.out", "w", stdout); process(); return 0; }

Compilation message (stderr)

savez.cpp:6: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    6 | #pragma GCC optimization ("O3")
      | 
savez.cpp:7: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    7 | #pragma GCC optimization ("unroll-loops")
      |
#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...