# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
100196 | sofhiasouza | Rima (COCI17_rima) | C++14 | 548 ms | 18896 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define MAXN 500010
#define pb push_back
#define inf 0x3f3f3f3f
using namespace std;
int n, dp[MAXN];
vector < string > vet;
inline bool cmp(string a, string b)
{
if(a.size() > b.size()) return true;
else if(a.size() < b.size()) return false;
return a < b;
}
inline int func(int i)
{
if(i == n-1) return 1;
if(dp[i] != -1) return dp[i];
string eu = vet[i];
eu.pop_back();
int r = 1;
if(vet[i+1].size() == eu.size())
{
if(vet[i+1] == eu) r = func(i+1) + 1;
}
else if(vet[i+1].size() - 1 == eu.size())
{
string k = vet[i+1];
k.pop_back();
if(k == eu) r = func(i+1) + 1;
}
return dp[i] = r;
}
int main()
{
cin >> n;
memset(dp, -1, sizeof dp);
for(int i = 0 ; i < n ; i++)
{
string s;
cin >> s;
reverse(s.begin(), s.end());
vet.pb(s);
}
sort(vet.begin(), vet.end(), cmp);
int resp = 0;
for(int i = 0 ; i < n ; i++)
{
resp = max(resp, func(i));
// cout << i << ' ' << resp << endl;
}
cout << resp << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |