# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
250955 | kingfran1907 | Savez (COCI15_savez) | C++14 | 109 ms | 17912 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const int maxn = 2e6+10;
const llint base = 31337;
const llint mod = 1e9+9;
int n;
map< llint, int > dp;
llint pot[maxn];
vector< llint > v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
pot[0] = 1;
for (int i = 1; i < maxn; i++)
pot[i] = pot[i - 1] * base, pot[i] %= mod;
int sol = 0;
while (n--) {
string a;
cin >> a;
v.clear();
v.push_back(0);
for (int i = 0; i < a.size(); i++) {
llint tren = v.back() * base;
tren %= mod;
tren += a[i], tren %= mod;
v.push_back(tren);
}
int tren = 0;
for (int i = 1; i < v.size(); i++) {
//printf("debug: %d/%d\n", i, v.size());
//printf("has: %lld == %lld\n", v[i], (v.back() - ((v[v.size() - 1 - i] * pot[i]) % mod) + mod) % mod);
if (v[i] == (v.back() - ((v[v.size() - 1 - i] * pot[i]) % mod) + mod) % mod)
tren = max(tren, dp[v[i]]);
}
tren++;
sol = max(sol, tren);
int &ac = dp[v.back()];
ac = max(ac, tren);
}
printf("%d", sol);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |