# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
959203 |
2024-04-07T16:33:15 Z |
Ariadna |
Savez (COCI15_savez) |
C++14 |
|
1000 ms |
46672 KB |
#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;
bool control = true;
for (int j = i+1; j < n && control; ++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]) {
control = false;
prefix = false;
} else 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()-k-1] != 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];
sort(x.begin(), x.end());
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 |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
3052 KB |
Output is correct |
2 |
Incorrect |
208 ms |
3068 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
604 KB |
Output is correct |
2 |
Correct |
156 ms |
2476 KB |
Output is correct |
3 |
Incorrect |
183 ms |
2628 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1042 ms |
3408 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1053 ms |
4956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1049 ms |
7428 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1025 ms |
10320 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1014 ms |
28240 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1031 ms |
46672 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |