Submission #1000466

#TimeUsernameProblemLanguageResultExecution timeMemory
1000466MilosMilutinovicRima (COCI17_rima)C++14
14 / 140
1099 ms17896 KiB
#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]; } for (int i = 0; i < n; i++) { reverse(s[i].begin(), s[i].end()); } auto Good = [&](string s, string t) { if (s.size() > t.size()) { swap(s, t); } int p = 0; while (p < (int) s.size() && s[p] == t[p]) { p += 1; } return p >= (int) t.size() - 1; }; sort(s.begin(), s.end(), [&](string a, string b) { if ((int) a.size() != (int) b.size()) { return a < b; } else { return (int) a.size() < (int) b.size(); } }); vector<int> dp(n); for (int i = 0; i < n; i++) { int mx = 0; for (int j = 0; j < i; j++) { if (Good(s[i], s[j])) { mx = max(mx, dp[j]); } } dp[i] = mx + 1; } cout << *max_element(dp.begin(), dp.end()) << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...