# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
305328 | FlashGamezzz | Rima (COCI17_rima) | C++17 | 618 ms | 89936 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
int lets[1000000][26] = {}, inds[1000000] = {}, par[1000000], dp[500000] = {}, winds[500000], sz = 1, ind, ans = 0;
vector<string> strs;
string s;
void add(int c, int i){
if (i == s.length()){
inds[c] = ind+1; winds[ind] = c;
return;
}
int l = int(s[s.length()-i-1])-97;
if (lets[c][l] == 0){
lets[c][l] = sz; par[sz] = c, sz++;
}
add(lets[c][l], i+1);
}
bool comp(string a, string b){
if (a.length() == b.length()){
return a < b;
}
return a.length() < b.length();
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
for (int i = 0; i < n; i++){
string s; cin >> s;
strs.push_back(s);
}
sort(strs.begin(), strs.end(), comp);
for (int i = 0; i < n; i++){
s = strs[i]; ind = i;
add(0, 0);
}
dp[0] = 1;
for (int i = 1; i < n; i++){
int pi = par[winds[i]], fr = -1;
dp[i] = 1;
if (inds[pi] > 0){
fr = inds[pi]-1;
}
for (int j = 0; lets[pi][j] != winds[i]; j++){
if (inds[lets[pi][j]] > 0){
fr = inds[lets[pi][j]]-1;
}
}
if (fr > -1){
dp[i] += dp[fr];
}
ans = max(ans, dp[i]);
}
cout << ans << endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |