답안 #151327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
151327 2019-09-02T13:11:04 Z GioChkhaidze Type Printer (IOI08_printer) C++14
0 / 100
73 ms 18896 KB
#include <bits/stdc++.h>
using namespace std;
int n,M;
string s[25005];
int Ts=1,T[25005*20][26];
bool Leaf[25005*36],f[25005*20];
void Add (int Id,int idx,int i) {
    int t=s[idx][i]-'a';
    if (i==s[idx].size()) return ;
    if (!T[Id][t]) T[Id][t]=++Ts;
    if (i+1==s[idx].size()) Leaf[T[Id][t]]=1;
    Add(T[Id][t],idx,i+1);
}

void F(int Id,int i) {
    int t=s[M][i]-'a';
    f[Id]=1;
    if (i==s[M].size()) return ;
    F(T[Id][t],i+1);
}

void Dfs (int Id,int i) {
    if (Leaf[Id]) printf("P \n");

    int In=-1;

    for (int t=0; t<26; t++)
        if (T[Id][t])
            if (f[T[Id][t]]) In=t;
                else {
                printf("%c\n",t+'a');
                Dfs(T[Id][t],i+1);
            }

    if (In!=-1) { printf("%c\n",In+'a'); Dfs(T[Id][In],i+1); }
    if (!f[Id]) printf("- \n");
}

main () {
    cin>>n;

    for (int i=1; i<=n; i++) {
        cin>>s[i];
        if (i==1) M=i;
            else
        if (s[i].size()>s[M].size()) M=i;
        Add(1,i,0);
    }

    F(1,0);
    printf("%d\n",(Ts-1)*2-s[M].size()+n);
    Dfs(1,0);
}

Compilation message

printer.cpp: In function 'void Add(int, int, int)':
printer.cpp:9:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (i==s[idx].size()) return ;
         ~^~~~~~~~~~~~~~~
printer.cpp:11:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (i+1==s[idx].size()) Leaf[T[Id][t]]=1;
         ~~~^~~~~~~~~~~~~~~
printer.cpp: In function 'void F(int, int)':
printer.cpp:18:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (i==s[M].size()) return ;
         ~^~~~~~~~~~~~~
printer.cpp: In function 'void Dfs(int, int)':
printer.cpp:28:12: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
         if (T[Id][t])
            ^
printer.cpp: At global scope:
printer.cpp:39:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
printer.cpp: In function 'int main()':
printer.cpp:51:41: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::__cxx11::basic_string<char>::size_type {aka long unsigned int}' [-Wformat=]
     printf("%d\n",(Ts-1)*2-s[M].size()+n);
                   ~~~~~~~~~~~~~~~~~~~~~~^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1184 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1144 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1144 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1144 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1144 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 1916 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 3832 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 8056 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 73 ms 18896 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 61 ms 14836 KB Line "P " doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -