답안 #531373

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531373 2022-02-28T14:32:51 Z yutabi Type Printer (IOI08_printer) C++14
0 / 100
72 ms 37656 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back

struct node
{
    node* child[26];

    bool en_buyuk;
    bool count;

    node()
    {
        for(int i=0;i<26;i++)
        {
            child[i]=NULL;

            en_buyuk=0;
            count=0;
        }
    }
};


int n;

vector <string> str;

int maxi;
int ptr;

node start;

node* curr;

vector <char> ans;

void DFS(node* nd)
{
    if(nd->count)
    {
        ans.pb('P');
    }

    vector <node*> ord;
    node* mx=NULL;

    vector <char> ord_ch;
    char mx_ch;
    
    for(int i=0;i<26;i++)
    {
        if(nd->child[i]!=NULL)
        {
            if(nd->child[i]->en_buyuk)
            {
                mx=nd->child[i];
                mx_ch=i;
            }

            else
            {
                ord.pb(nd->child[i]);
                ord_ch.pb(i);

                printf("%c\n",ord_ch.back()+'a');
            }
        }
    }
    
    if(mx!=NULL)
    {
        ord.pb(mx);
        ord_ch.pb(mx_ch);
    }

    for(int i=0;i<ord.size();i++)
    {
        ans.pb(ord_ch[i]+'a');
        DFS(ord[i]);
    }

    if(nd->en_buyuk==0)
    {
        ans.pb('-');
    }
}

int main()
{
    cin >> n;

    str=vector <string> (n);

    for(int i=0;i<n;i++)
    {
        cin >> str[i];

        if(str[i].size()>maxi)
        {
            maxi=str[i].size();
            ptr=i;
        }
    }

    start.en_buyuk=1;

    for(int i=0;i<n;i++)
    {
        curr=&start;

        for(int j=0;j<str[i].size();j++)
        {
            if(curr->child[str[i][j]-'a']==NULL)
            {
                node *nw = new node;

                curr->child[str[i][j]-'a']=nw;
            }

            curr=curr->child[str[i][j]-'a'];

            if(j+1==str[i].size())
            {
                curr->count=1;
            }

            if(i==ptr)
            {
                curr->en_buyuk=1;
            }
        }
    }

    DFS(&start);

    printf("%lu\n",ans.size());
    
    for(int i=0;i<ans.size();i++)
    {
        printf("%c\n",ans[i]);
    }
}

Compilation message

printer.cpp: In function 'void DFS(node*)':
printer.cpp:78:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<node*>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |     for(int i=0;i<ord.size();i++)
      |                 ~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:100:25: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
  100 |         if(str[i].size()>maxi)
      |            ~~~~~~~~~~~~~^~~~~
printer.cpp:113:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |         for(int j=0;j<str[i].size();j++)
      |                     ~^~~~~~~~~~~~~~
printer.cpp:124:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  124 |             if(j+1==str[i].size())
      |                ~~~^~~~~~~~~~~~~~~
printer.cpp:140:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  140 |     for(int i=0;i<ans.size();i++)
      |                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Expected integer, but "b" found
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 280 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 1868 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 6084 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 31 ms 15160 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 72 ms 37656 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 29684 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -