답안 #49246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49246 2018-05-24T09:56:01 Z rzbt Rima (COCI17_rima) C++14
0 / 140
2 ms 604 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define MAXN 3000005
typedef long long ll;

using namespace std;
int trie[MAXN][30];
int n;
char s[MAXN];
bool kraj[MAXN];
int cvor=1;
int sz;
int res=0;
int dfs(int t){
    //printf("   %d\n",t);
    int br=0, mx=0;

    for(int i=0;i<30;i++){
        if(trie[t][i]){
            int tmp=dfs(trie[t][i]);
            if(tmp){
                br++;
                mx=max(mx,tmp);
            }
        }

    }
    res=max(res,br+mx-1);
    if(kraj[t])return (br?br+mx:1);
    return 0;
}

int main()
{
    scanf("%d", &n);
    for(int i=0;i<n;i++){
        scanf("%s",s);
        sz=strlen(s);
        reverse(s,s+sz);

        int tren=0;
        for(int j=0;j<sz;j++){
            if(trie[tren][s[j]-'a'])
                tren=trie[tren][s[j]-'a'];
            else{
                trie[tren][s[j]-'a']=cvor;
                cvor++;
                tren=trie[tren][s[j]-'a'];
            }
        }
        kraj[tren]=true;
    }
    dfs(0);
    printf("%d",res);
    return 0;
}

Compilation message

rima.cpp: In function 'int main()':
rima.cpp:39:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
rima.cpp:41:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",s);
         ~~~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 256 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 1 ms 356 KB Execution killed with signal 11 (could be triggered by violating memory limits)
3 Runtime error 1 ms 388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Runtime error 1 ms 388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 2 ms 480 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 1 ms 480 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 1 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 1 ms 576 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 1 ms 604 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 2 ms 604 KB Execution killed with signal 11 (could be triggered by violating memory limits)