답안 #520670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
520670 2022-01-30T17:23:25 Z kakayoshi Rima (COCI17_rima) C++14
56 / 140
272 ms 110448 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pi;
typedef pair<pair<ll, ll>,ll > pii;
typedef vector <ll> vi;
#define forw(i,a,b) for (ll i=a;i<=(b);i++)
#define forb(i,a,b) for (ll i=a;i>=(b);i--)
#define fast {ios::sync_with_stdio(false); cin.tie(0); }
#define fi first
#define se second
#define pu push
#define puf push_front
#define pb push_back
#define pof pop_front
#define pob pop_back
#define fr front
#define all(a) a.begin(),a.end()
const ll oo=1e18;
const ll mod=1337377;
const int base=31;
const int tx[5]={0,-1,0,1,0};
const int ty[5]={0,0,1,0,-1};
const ll maxN=3e5+5;
const ll maxM=1e6+5;
const ll block=700;
int out, save[maxM][30],dem,n;
bool ed[maxM];
vector <int> edge[maxM];
pi largest[maxM];
void update(int &nhat, int &nhi, int val)
{
    if (val>=nhat)
    {
        nhi=nhat;
        nhat=val;
    }
    else
        if (val>=nhi) nhi=val;
    return;
}
void dfs(int u)
{
    largest[u]={0,0};
    int tmp=0;
    for(auto v:edge[u])
    {
        tmp+=ed[v];
        dfs(v);
        update(largest[u].fi,largest[u].se,largest[v].fi);
    }
    tmp-=(largest[u].fi>0);
    tmp-=(largest[u].se>0);
    out=max(out,largest[u].fi+largest[u].se+(ed[u]==1)+tmp);
    if (!ed[u]) largest[u]={0,0};
    else largest[u].fi=largest[u].fi+largest[u].se+1+tmp;
    return;
}
void solve()
{
    cin>>n;
    forw(i,1,n)
    {
        string s;cin>>s;
        int id=0;
        reverse(all(s));
        for(auto c:s)
        {
            if (save[id][c-'a']==0)
            {
                save[id][c-'a']=++dem;
                edge[id].pb(dem);
            }
            id=save[id][c-'a'];
        }
        ed[id]=1;
    }
    // build
    dfs(0);
    cout<<out;
}
int main()
{
    fast;
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
    int t=1; //cin>>t;
    while (t--)
        solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23756 KB Output is correct
2 Correct 13 ms 23832 KB Output is correct
3 Correct 13 ms 23852 KB Output is correct
4 Incorrect 272 ms 110448 KB Output isn't correct
5 Correct 28 ms 24388 KB Output is correct
6 Incorrect 66 ms 94560 KB Output isn't correct
7 Incorrect 62 ms 94460 KB Output isn't correct
8 Incorrect 64 ms 94492 KB Output isn't correct
9 Incorrect 83 ms 96200 KB Output isn't correct
10 Incorrect 60 ms 94500 KB Output isn't correct