# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
94835 |
2019-01-24T11:11:28 Z |
quoriess |
Rima (COCI17_rima) |
C++14 |
|
481 ms |
150376 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<lli,lli> pii;
#define dbg(x) //cout<<#x<<" has a value of: "<<x<<"\n";
#define usize(x) (int)(x.size())
#define plist(x) for(int i=0;i<usize(x);i++)cout<<"eleman "<<i<<" = "<<x[i]<<"\n";
#define foreach(x) for(auto item:x)
#define fill(s,x) for(int i=0;i<x;i++)cin>>s[i];
#define in(veriler,a) (veriler.find(a)!=veriler.end())
#define btw(x,y,z) x>=y && x<=z
#define ord(x) x-'a'
std::ostream& operator<<(std::ostream& os, pair<int,int> p) {
os << p.first << ", " << p.second;
return os;
}
const int ALPHABET_SIZE=26;
struct TrieNode{
TrieNode* children[ALPHABET_SIZE];
int isendsy;
int dp;
};
TrieNode* mkTrieNode(){
TrieNode* pnode=new TrieNode;
pnode->isendsy=0;
for (int i = 0; i < ALPHABET_SIZE; i++)
{
pnode->children[i]=NULL;
}
return pnode;
}
void addString(TrieNode* root,string str){
TrieNode* v=root;
for (int i = 0; i < usize(str); i++)
{
if(!v->children[ord(str[i])])
v->children[ord(str[i])]=mkTrieNode();
v=v->children[ord(str[i])];
}
v->isendsy++;
}
int glmx=-1;
void dfs(TrieNode* n){
int d=0, mxd=-1;
int s=0;
for (int i = 0; i < ALPHABET_SIZE; i++)
{
if(n->children[i]){
dbg((char)(i+'a'));
dfs(n->children[i]);
if(n->children[i]->isendsy){
s+=n->children[i]->isendsy;
if(n->children[i]->dp>d){
d=n->children[i]->dp;
mxd=i;
}
}
}
}
int rn=n->isendsy+s+d-(mxd!=-1?n->children[mxd]->isendsy:0);
n->dp=min(n->isendsy,1)*rn;
dbg(n->dp);
glmx=max(glmx,n->dp);
}
int main(){
int n;
cin>>n;
vector<string> dizi;
for (int i = 0; i < n; i++)
{
string s;
cin>>s;
reverse(s.begin(),s.end());
dizi.push_back(s);
}
sort(dizi.begin(),dizi.end());
TrieNode* root=mkTrieNode();
foreach(dizi){
addString(root,item);
}
dfs(root);
cout<<glmx<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Incorrect |
481 ms |
150376 KB |
Output isn't correct |
5 |
Correct |
115 ms |
3960 KB |
Output is correct |
6 |
Incorrect |
122 ms |
81652 KB |
Output isn't correct |
7 |
Incorrect |
116 ms |
81996 KB |
Output isn't correct |
8 |
Incorrect |
117 ms |
81616 KB |
Output isn't correct |
9 |
Incorrect |
200 ms |
87984 KB |
Output isn't correct |
10 |
Incorrect |
96 ms |
81388 KB |
Output isn't correct |