Submission #100196

#TimeUsernameProblemLanguageResultExecution timeMemory
100196sofhiasouzaRima (COCI17_rima)C++14
42 / 140
548 ms18896 KiB
#include <bits/stdc++.h> #define MAXN 500010 #define pb push_back #define inf 0x3f3f3f3f using namespace std; int n, dp[MAXN]; vector < string > vet; inline bool cmp(string a, string b) { if(a.size() > b.size()) return true; else if(a.size() < b.size()) return false; return a < b; } inline int func(int i) { if(i == n-1) return 1; if(dp[i] != -1) return dp[i]; string eu = vet[i]; eu.pop_back(); int r = 1; if(vet[i+1].size() == eu.size()) { if(vet[i+1] == eu) r = func(i+1) + 1; } else if(vet[i+1].size() - 1 == eu.size()) { string k = vet[i+1]; k.pop_back(); if(k == eu) r = func(i+1) + 1; } return dp[i] = r; } int main() { cin >> n; memset(dp, -1, sizeof dp); for(int i = 0 ; i < n ; i++) { string s; cin >> s; reverse(s.begin(), s.end()); vet.pb(s); } sort(vet.begin(), vet.end(), cmp); int resp = 0; for(int i = 0 ; i < n ; i++) { resp = max(resp, func(i)); // cout << i << ' ' << resp << endl; } cout << resp << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...