Submission #785949

#TimeUsernameProblemLanguageResultExecution timeMemory
785949MilosMilutinovicRima (COCI17_rima)C++14
14 / 140
1093 ms18016 KiB
/** * author: wxhtzdy * created: 17.07.2023 22:01:28 **/ #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; } auto Check = [&](string s, string t) { int ptr = 0; int si = (int) s.size(); int sj = (int) t.size(); while (ptr < min(si, sj) && s[si - ptr - 1] == t[sj - ptr - 1]) { ptr += 1; } return (ptr >= max(si, sj) - 1); }; vector<int> dp(n); for (int i = 0; i < n; i++) { dp[i] = 1; for (int j = 0; j < i; j++) { if (Check(s[i], s[j])) { dp[i] = max(dp[i], dp[j] + 1); } } } cout << *max_element(dp.begin(), dp.end()) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...