# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
604023 |
2022-07-24T15:29:02 Z |
inksamurai |
Savez (COCI15_savez) |
C++17 |
|
487 ms |
63056 KB |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=(c);i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3aFGabX ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e
// kactl : Z function
vi Z(string S) {
vi z(sz(S));
int l = -1, r = -1;
rng(i,1,sz(S)) {
z[i] = i >= r ? 0 : min(r - i, z[i - l]);
while (i + z[i] < sz(S) && S[i + z[i]] == S[z[i]])
z[i]++;
if (i + z[i] > r)
l = i, r = i + z[i];
}
return z;
}
signed main(){
_3aFGabX;
int n;
cin>>n;
vec(string) a,tmp;
rep(i,n){
string s;
cin>>s;
a.pb(s);
string rs=s;
reverse(rs.begin(), rs.end());
tmp.pb(rs);
}
sort(tmp.begin(), tmp.end());
tmp.erase(unique(tmp.begin(), tmp.end()),tmp.end());
const int m=sz(tmp);
// sort(a.begin(), a.end(),[&](const string&l,const string&r){
// return sz(l)<sz(r);
// });
vi dp(m,0);
rep(i,n){
vi z=Z(a[i]);
// rep(j,sz(a[i])){
// cout<<z[j]<<" ";
// }
// print("....");
int id=(int)(lower_bound(tmp.begin(), tmp.end(),a[i])-tmp.begin());
string now="";
int res=dp[id];
per(j,sz(a[i])){
now+=a[i][j];
if(!j or z[j]==sz(a[i])-j){
if(lower_bound(tmp.begin(), tmp.end(),now)!=tmp.end()){
int ni=(int)(lower_bound(tmp.begin(), tmp.end(),now)-tmp.begin());
// if(i==2) print(ni);
res=max(res,dp[ni]+1);
}
}
}
dp[id]=res;
// print(id,dp[id],a[i]);
}
print(*max_element(dp.begin(), dp.end()));
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Incorrect |
3 ms |
468 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
2272 KB |
Output is correct |
2 |
Correct |
144 ms |
2260 KB |
Output is correct |
3 |
Correct |
487 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
186 ms |
3044 KB |
Output is correct |
3 |
Correct |
363 ms |
2440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
3020 KB |
Output is correct |
2 |
Correct |
86 ms |
3184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
4016 KB |
Output is correct |
2 |
Correct |
65 ms |
4032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
71 ms |
5436 KB |
Output is correct |
2 |
Correct |
69 ms |
5396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
76 ms |
8120 KB |
Output is correct |
2 |
Correct |
76 ms |
7784 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
103 ms |
15528 KB |
Output is correct |
2 |
Correct |
100 ms |
15568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
174 ms |
25620 KB |
Output is correct |
2 |
Correct |
161 ms |
25556 KB |
Output is correct |
3 |
Correct |
330 ms |
63056 KB |
Output is correct |