Submission #94841

#TimeUsernameProblemLanguageResultExecution timeMemory
94841quoriessRima (COCI17_rima)C++14
56 / 140
528 ms151356 KiB
#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 x){ //x=n'nin ata+kardeş sayısı int nos=0; for (int i = 0; i < ALPHABET_SIZE; i++) { if(n->children[i])nos+=n->children[i]->isendsy; } for (int i = 0; i < ALPHABET_SIZE; i++) { if(n->children[i]){ if(n->isendsy && n->children[i]->isendsy)dfs(n->children[i],nos+x); else if(n->isendsy && !n->children[i]->isendsy) dfs(n->children[i],0); else if(!n->isendsy && n->children[i]->isendsy) dfs(n->children[i],nos); else if(!n->isendsy && !n->children[i]->isendsy) dfs(n->children[i],0); } } if(n->isendsy)glmx=max(x,glmx); } 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,0); cout<<glmx<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...