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>
using namespace std;
vector<int> dp;
int solve(int i, int n, vector<string>& x) {
if (dp[i] != -1) return dp[i];
dp[i] = 1;
for (int j = i+1; j < n; ++j) {
if ((int)x[i].size() > (int)x[j].size()) continue;
bool prefix = true, suffix = true;
for (int k = 0; k < (int)x[i].size() && prefix; ++k) {
if (x[j][k] != x[i][k]) prefix = false;
}
if (!prefix) continue;
for (int k = 0; k < (int)x[i].size() && suffix; ++k) {
if (x[j][(int)x[j].size() - (int)x[i].size() + k] != x[i][k]) suffix = false;
}
if (!suffix) continue;
dp[i] = max(dp[i], 1 + solve(j, n, x));
}
return dp[i];
}
int main() {
int n;
cin >> n;
vector<string> x(n);
dp = vector<int>(n, -1);
for (int i = 0; i < n; ++i) cin >> x[i];
int ans = 0;
for (int i = 0; i < n; ++i) {
if (dp[i] == -1) ans = max(ans, solve(i, n, x));
}
cout << ans << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |