답안 #434418

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
434418 2021-06-21T09:17:26 Z Trunkty Type Printer (IOI08_printer) C++14
0 / 100
1 ms 204 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Node{
    bool print;
    int arr[125];
};

int n,nextnode=1;
Node trie[500005]; 
int maxi;
string final,ans;

void build(int node, string a, int ind){
    if(ind==a.length()){
        trie[node].print = true;
        return;
    }
    if(trie[node].arr[a[ind]]==-1){
        trie[node].arr[a[ind]] = nextnode;
        for(int i='a';i<='z';i++){
            trie[nextnode].arr[i] = -1;
        }
        nextnode++;
    }
    build(trie[node].arr[a[ind]],a,ind+1);
}

void pnt(int node, int ind){
    if(trie[node].print){
        ans += 'P';
    }
    if(ind==final.length()){
        ans += 45;
        return;
    }
    for(char i='a';i<='z';i++){
        if(i==final[ind]){
            continue;
        }
        if(trie[node].arr[i]!=-1){
            ans += i;
            pnt(trie[node].arr[i],ind+1);
        }
    }
    if(trie[node].arr[final[ind]]!=-1){
        ans += final[ind];
        pnt(trie[node].arr[final[ind]],ind+1);
    }
    ans += 45;
}

int main(){
    freopen("type.in","r",stdin);
    freopen("type.out","w",stdout);
    cin >> n;
    for(int i='a';i<='z';i++){
        trie[0].arr[i] = -1;
    }
    for(int i=1;i<=n;i++){
        string a;
        cin >> a;
        build(0,a,0);
        if(a.length()>maxi){
            maxi = a.length();
            final = a;
        }
    }
    pnt(0,0);
    cout << ans.length()-final.length()-1 << "\n";
    for(int i=0;i<ans.length()-final.length()-1;i++){
        cout << ans[i] << "\n";
    }
    return 0;
}

Compilation message

printer.cpp: In function 'void build(int, std::string, int)':
printer.cpp:17:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     if(ind==a.length()){
      |        ~~~^~~~~~~~~~~~
printer.cpp:21:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   21 |     if(trie[node].arr[a[ind]]==-1){
      |                             ^
printer.cpp:22:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   22 |         trie[node].arr[a[ind]] = nextnode;
      |                              ^
printer.cpp:28:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   28 |     build(trie[node].arr[a[ind]],a,ind+1);
      |                                ^
printer.cpp: In function 'void pnt(int, int)':
printer.cpp:35:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     if(ind==final.length()){
      |        ~~~^~~~~~~~~~~~~~~~
printer.cpp:43:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   43 |         if(trie[node].arr[i]!=-1){
      |                           ^
printer.cpp:45:32: warning: array subscript has type 'char' [-Wchar-subscripts]
   45 |             pnt(trie[node].arr[i],ind+1);
      |                                ^
printer.cpp:48:33: warning: array subscript has type 'char' [-Wchar-subscripts]
   48 |     if(trie[node].arr[final[ind]]!=-1){
      |                                 ^
printer.cpp:50:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   50 |         pnt(trie[node].arr[final[ind]],ind+1);
      |                                      ^
printer.cpp: In function 'int main()':
printer.cpp:66:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |         if(a.length()>maxi){
      |            ~~~~~~~~~~^~~~~
printer.cpp:73:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |     for(int i=0;i<ans.length()-final.length()-1;i++){
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:56:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |     freopen("type.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:57:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |     freopen("type.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -