답안 #57726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
57726 2018-07-15T23:07:14 Z vex Type Printer (IOI08_printer) C++14
80 / 100
1000 ms 99908 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;
}
void sredi(string s)
{
    Node* curr=head;
    curr->in=true;
    for(int i=0;i<s.size();i++)
    {
        int zn=s[i]-'a';
        curr=curr->deca[zn];
        curr->in=true;
    }
}
void ispisi(Node* v)
{
    if(v->kraj)cout<<"P"<<endl;

    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)<<endl;
            ispisi(nv);
            cout<<"-"<<endl;
        }
    }

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

int n;
int maxx=0;
string x[MAXN];
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[i];
        ubaci(x[i]);
        if(x[i].size()>x[maxx].size())maxx=i;
    }

    sredi(x[maxx]);
    cout<<2*br-2+n-x[maxx].size()<<endl;
    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 'void sredi(std::__cxx11::string)':
printer.cpp:40:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++)
                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1144 KB Output is correct
2 Correct 3 ms 1252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1332 KB Output is correct
2 Correct 3 ms 1376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1376 KB Output is correct
2 Correct 2 ms 1412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1412 KB Output is correct
2 Correct 3 ms 1412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1480 KB Output is correct
2 Correct 16 ms 2120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2888 KB Output is correct
2 Correct 34 ms 3292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 7020 KB Output is correct
2 Correct 198 ms 13420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 240 ms 15624 KB Output is correct
2 Correct 68 ms 15624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 554 ms 37336 KB Output is correct
2 Execution timed out 1092 ms 84512 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 423 ms 84512 KB Output is correct
2 Execution timed out 1075 ms 99908 KB Time limit exceeded
3 Halted 0 ms 0 KB -