제출 #701359

#제출 시각아이디문제언어결과실행 시간메모리
701359fdnfksdRima (COCI17_rima)C++14
0 / 140
13 ms16040 KiB
#include<bits/stdc++.h> #define TASKNAME "bieudo" #define pb push_back #define pli pair<int,int> #define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); using namespace std; using ll=int; const ll maxN=5e5+10; const ll inf=1e18; const ll mod=1e9+7; struct TrieNode { ll val; TrieNode* child[26]; ll ct; TrieNode() { val=0; ct=0; for(int i=0;i<26;i++) child[i]=nullptr; } }; TrieNode *root=new TrieNode(); void add(string s) { auto p=root; ll n=s.size()-1; for(int i=1;i<=n;i++) { if(p->child[s[i]-'a']==nullptr) { p->child[s[i]-'a']=new TrieNode(); } p=p->child[s[i]-'a']; } p->ct++; } ll ans=0; void dfs(TrieNode* u) { vector<ll> vec; for(int i=0;i<26;i++) { if(u->child[i]!=nullptr) { dfs(u->child[i]); auto v=u->child[i]; if(v->ct>0) { vec.pb(v->val); } } } ll bonus=u->ct; sort(vec.begin(),vec.end(),greater<int>()); if(vec.size()==0) u->val=bonus; else { u->val=bonus+vec.size()-1+vec[0]; } ans=max(ans,u->val); if(vec.size()>=2) { ans=max(ans,bonus+(ll)vec.size()-2+vec[0]+vec[1]); } } ll n; string s[maxN]; bool check(ll i,ll j) { ll cc=min(s[i].size()-1,s[j].size()-1); ll ans=cc; for(int k=1;k<=cc;k++) { if(s[i][k]!=s[j][k]) { ans=k-1; break; } } return ans>=max(s[i].size()-1,s[j].size()-1)-1; } ll dp[maxN]; void solve() { cin >> n; //ll ans=0; for(int i=1;i<=n;i++) { cin >> s[i]; reverse(s[i].begin(),s[i].end()); s[i]=' '+s[i]; add(s[i]); } dfs(root); cout << ans; } int main() { fastio freopen(TASKNAME".INP","r",stdin); //freopen(TASKNAME".OUT","w",stdout); solve(); }

컴파일 시 표준 에러 (stderr) 메시지

rima.cpp:9:14: warning: overflow in conversion from 'double' to 'll' {aka 'int'} changes value from '1.0e+18' to '2147483647' [-Woverflow]
    9 | const ll inf=1e18;
      |              ^~~~
rima.cpp: In function 'bool check(ll, ll)':
rima.cpp:81:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'long unsigned int' [-Wsign-compare]
   81 |     return ans>=max(s[i].size()-1,s[j].size()-1)-1;
      |            ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
rima.cpp: In function 'int main()':
rima.cpp:101:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |     freopen(TASKNAME".INP","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...