답안 #57729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57729 2018-07-15T23:44:12 Z vex Type Printer (IOI08_printer) C++14
100 / 100
210 ms 98788 KB
#include <bits/stdc++.h>
#define MAXN 25005
#define ALPH 26
using namespace std;

int br=1;
struct Node{
    bool in;
    bool kraj;
    struct Node* deca[ALPH];
}* head;

void init()
{
    head=new Node();
    head->kraj=false;
    head->in=false;
}
void ubaci(string s)
{
    Node* curr=head;
    for(int i=0;i<s.size();i++)
    {
        int zn=s[i]-'a';
        if(curr->deca[zn]==NULL)
        {
            curr->deca[zn]=new Node();
            curr->deca[zn]->kraj=false;
            curr->deca[zn]->in=false;
            br++;
        }
        curr=curr->deca[zn];
    }
    curr->kraj=true;
}
int maxx=0;
string naj;
void sredi()
{
    Node* curr=head;
    curr->in=true;
    for(int i=0;i<maxx;i++)
    {
        int zn=naj[i]-'a';
        curr=curr->deca[zn];
        curr->in=true;
    }
}
void ispisi(Node* v)
{
    if(v->kraj)cout<<"P"<<"\n";

    int ind=-1;
    for(int i=0;i<ALPH;i++)if(v->deca[i]!=NULL)
    {
        Node* nv=v->deca[i];
        if(nv->in)ind=i;
        else
        {
            cout<<char('a'+i)<<"\n";
            ispisi(nv);
            cout<<"-"<<"\n";
        }
    }

    if(ind!=-1)
    {
        cout<<char('a'+ind)<<"\n";
        ispisi(v->deca[ind]);
    }
}

int n;
string x;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    init();
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        ubaci(x);
        if( x.size() > maxx ){
			maxx = x.size();
			naj = x;
		}
    }

    sredi();
    cout<<2*br-2+n-maxx<<"\n";
    ispisi(head);
    return 0;
}

Compilation message

printer.cpp: In function 'void ubaci(std::__cxx11::string)':
printer.cpp:22:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++)
                 ~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:87:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if( x.size() > maxx ){
             ~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 428 KB Output is correct
2 Correct 2 ms 476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 536 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 624 KB Output is correct
2 Correct 3 ms 624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 3 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2028 KB Output is correct
2 Correct 6 ms 2428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 6092 KB Output is correct
2 Correct 25 ms 12556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 14736 KB Output is correct
2 Correct 17 ms 14736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 36340 KB Output is correct
2 Correct 172 ms 82828 KB Output is correct
3 Correct 103 ms 82828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 82828 KB Output is correct
2 Correct 210 ms 98788 KB Output is correct
3 Correct 94 ms 98788 KB Output is correct
4 Correct 166 ms 98788 KB Output is correct