# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
165412 |
2019-11-27T06:58:37 Z |
Atill83 |
Savez (COCI15_savez) |
C++14 |
|
241 ms |
16744 KB |
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 2e6+5;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
string s;
map<ll, ll> mp;
ll pw[MAXN];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
#ifdef Local
freopen("../IO/int.txt","r",stdin);
freopen("../IO/out.txt","w",stdout);
#endif
cin>>n;
pw[0] = 1;
for(int i = 1; i < MAXN; i++){
pw[i] = pw[i - 1]*37%mod;
}
ll ans = 0;
for(int i = 0; i < n; i++){
cin>>s;
ll hash = 0;
for(int j = 0; j < (int)s.length(); j++){
hash += (int)(s[j] - 'A' + 1)*pw[j];
hash %= mod;
}
ll cur = mp[hash];
//cout<<i<<" "<<hash<<endl;
ll curH = 0;
for(int l = 0; l < (int) s.length() - 1; l++){
curH += pw[l]*((int)(s[l] - 'A' + 1));
curH %= mod;
//cout<<l<<" ";
//cout<<curH<<endl;
//cout<<mp[curH]<<endl;
mp[hash] = max(mp[hash], mp[curH] + 1);
}
mp[hash] = max(mp[hash], cur + 1LL);
//cout<<mp[hash]<<endl;
ans = max(ans, mp[hash]);
}
cout<<ans<<endl;
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
15992 KB |
Output is correct |
2 |
Correct |
26 ms |
15992 KB |
Output is correct |
3 |
Incorrect |
26 ms |
16120 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
28 ms |
15992 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
16168 KB |
Output is correct |
2 |
Correct |
201 ms |
16580 KB |
Output is correct |
3 |
Correct |
179 ms |
16200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
16632 KB |
Output is correct |
2 |
Correct |
225 ms |
16724 KB |
Output is correct |
3 |
Correct |
241 ms |
16744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
155 ms |
16228 KB |
Output is correct |
2 |
Correct |
125 ms |
16252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
16176 KB |
Output is correct |
2 |
Correct |
97 ms |
16296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
119 ms |
16332 KB |
Output is correct |
2 |
Correct |
80 ms |
16376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
16248 KB |
Output is correct |
2 |
Correct |
103 ms |
16644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
15992 KB |
Output is correct |
2 |
Correct |
85 ms |
15984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
15992 KB |
Output is correct |
2 |
Correct |
81 ms |
16044 KB |
Output is correct |
3 |
Correct |
110 ms |
15992 KB |
Output is correct |