# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
55628 | polyfish | Rima (COCI17_rima) | C++14 | 1084 ms | 63872 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//I love armpit fetish
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"
const int MAX_N = 500002;
const int MOD = 1000000007;
int n, p[MAX_N];
int64_t H0[MAX_N], H1[MAX_N];
string s[MAX_N];
bool cmp(int a, int b) {
return s[a].size()>s[b].size();
}
void enter() {
cin >> n;
for (int i=1; i<=n; ++i)
cin >> s[i];
}
void init() {
for (int i=1; i<=n; ++i)
p[i] = i;
sort(p+1, p+n+1, cmp);
for (int i=1; i<=n; ++i) {
for (int j=(int)s[p[i]].size()-1; j>0; --j)
H0[i] = (H0[i] * 27 + s[p[i]][j] - 'a' + 1) % MOD;
H1[i] = (H0[i] * 27 + s[p[i]][0] - 'a' + 1) % MOD;
}
}
void solve() {
map<int64_t, int> mp;
int res = 0;
for (int i=1; i<=n; ++i) {
int tmp = max(mp[H0[i]], mp[H1[i]]) + 1;
res = max(res, tmp);
mp[H0[i]] = max(mp[H0[i]], tmp);
mp[H1[i]] = max(mp[H1[i]], tmp);
}
cout << res;
}
int main() {
//#define OFFLINE_JUDGE doraemon
#ifdef OFFLINE_JUDGE
freopen(FILE_NAME".inp", "r", stdin);
freopen(FILE_NAME".out", "w", stdout);
#endif
ios::sync_with_stdio(0); cin.tie(0);
enter();
init();
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |