# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
282171 |
2020-08-24T05:41:42 Z |
Fischer |
Rima (COCI17_rima) |
C++14 |
|
0 ms |
0 KB |
/**
* code generated by JHelper
* More info: https://github.com/AlexeyDmitriev/JHelper
* @author Miguel Mini
*/
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <complex>
#include <climits>
#include <iomanip>
#include <numeric>
#include <functional>
#include <fstream>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <stack>
#define sz(x) (int)x.size()
#define trav(v, x) for (auto v : x)
#define re(x, y, z) for (int x=y; x<z; ++x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define set_to(x, v) fill(all(x), v)
#define eb emplace_back
#define lso(x) ((x)&-(x))
#define mset(m ,v) memset(m, v, sizeof(m))
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using si = set<int>;
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 mod = 1e9 + 7;
int add(int a, int b, int m=mod) {
return a+b < m? a+b : a+b-m;
}
int mul(ll a, ll b, int m=mod) {
return a*b%m;
}
int ex(int a, int b, int m=mod) {
int r=1;
while (b > 0) {
if (b&1) r = mul(r, a, m);
a = mul(a, a, m);
b >>= 1;
}
return r;
}
const int inf = 1.2e9;
const int maxn = 5e5 + 10;
string s[maxn];
using ull = unsigned long long;
unordered_map<ull, int> memo[maxn];
unordered_map<ull, int> cnt[maxn];
class COCI17Rima {
public:
void solveOne(istream& in, ostream& out) {
int n;
in >> n;
re(i, 0, n) in >> s[i];
sort(s, s+n, [](const string& p, const string& q) {
return p.size() > q.size();
});
int res = 0;
re(i, 0, n) {
reverse(all(s[i]));
ull hash = 0;
re(j, 0, sz(s[i]) - 1) {
hash = (hash<<17) + hash + s[i][j];
}
cnt[sz(s[i])][hash] += 1;
}
re(i, 0, n) {
ll hash = 0;
re(j, 0, sz(s[i]) - 1) {
hash = (hash<<17) + hash + s[i][j];
}
int len = sz(s[i]);
int ans = cnt[len][hash] + memo[len+1][(hash<<17) + hash + s[i][len - 1]];
res = max(res, ans);
memo[len][hash] = max(memo[len][hash], ans);
}
out << res << endl;
}
void solve(istream& in, ostream& out) {
out.precision(10);
out << fixed;
int testNumber = 1;
//in >> testNumber;
re(tc, 1, testNumber+1) {
//out << "Case #" << tc << ": ";
solveOne(in, out);
}
}
};
int main() {
//freopen("in", "r", stdin);
//freopen("out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
COCI17Rima solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
Compilation message
rima.cpp:76:1: error: 'unordered_map' does not name a type
76 | unordered_map<ull, int> memo[maxn];
| ^~~~~~~~~~~~~
rima.cpp:77:1: error: 'unordered_map' does not name a type
77 | unordered_map<ull, int> cnt[maxn];
| ^~~~~~~~~~~~~
rima.cpp: In member function 'void COCI17Rima::solveOne(std::istream&, std::ostream&)':
rima.cpp:95:9: error: 'cnt' was not declared in this scope; did you mean 'int'?
95 | cnt[sz(s[i])][hash] += 1;
| ^~~
| int
rima.cpp:103:19: error: 'cnt' was not declared in this scope; did you mean 'int'?
103 | int ans = cnt[len][hash] + memo[len+1][(hash<<17) + hash + s[i][len - 1]];
| ^~~
| int
rima.cpp:103:36: error: 'memo' was not declared in this scope
103 | int ans = cnt[len][hash] + memo[len+1][(hash<<17) + hash + s[i][len - 1]];
| ^~~~