# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
564073 |
2022-05-18T14:08:04 Z |
perchuts |
Savez (COCI15_savez) |
C++17 |
|
1000 ms |
52428 KB |
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const ll mod = 1e9+7;
const ll base = 101;
const int maxn = 2e6+100;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
bool cmp(pair<int,string>a,pair<int,string>b){
if(a.first==b.first)return 1;
return a.first>b.first;
}
vector<vector<ll>>hsh, revHsh;
vector<pair<int,string>>v;
ll mul[maxn];
void computeHash(int idx){
int n = v[idx].first;
hsh[idx].pb(ll(v[idx].second[0]-'A'));
for(int i=1;i<n;++i){
hsh[idx].pb(hsh[idx].back()*base+ll(v[idx].second[i]-'A'));
hsh[idx].back() %= mod;
}
revHsh[idx].pb(ll(v[idx].second[n-1]-'A'));
for(int i=n-2;i>=0;--i){
revHsh[idx].pb(revHsh[idx].back()+mul[n-1-i]*ll(v[idx].second[i]-'A'));
revHsh[idx].back() %= mod;
}
}
map<ll,int>dp;
int main(){_
int n;cin>>n;
v.resize(n);
for(int i=0;i<n;++i){
cin>>v[i].second;
v[i].first = sz(v[i].second);
}
mul[0] = 1ll;
for(int i=1;i<maxn;++i)mul[i] = (mul[i-1]*base)%mod;
sort(all(v), cmp);
hsh.resize(n), revHsh.resize(n);
int best = 0;
for(int i=0;i<n;++i){
computeHash(i);
ll me = hsh[i][v[i].first-1];
int res = dp[me]+1;
for(int j=0;j<v[i].first;++j){
//termino aqui
if(hsh[i][j]!=revHsh[i][j])continue;
ckmax(dp[hsh[i][j]], res);
}
ckmax(best, res);
}
cout<<best<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
15956 KB |
Output is correct |
2 |
Incorrect |
17 ms |
15968 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
32336 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
35520 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
17680 KB |
Output is correct |
2 |
Correct |
59 ms |
36308 KB |
Output is correct |
3 |
Incorrect |
81 ms |
36812 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
118 ms |
41280 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
359 ms |
42532 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
19912 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1077 ms |
20836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
472 ms |
52428 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1067 ms |
32880 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |