Submission #959203

#TimeUsernameProblemLanguageResultExecution timeMemory
959203AriadnaSavez (COCI15_savez)C++14
0 / 120
1053 ms46672 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...