Submission #387389

# Submission time Handle Problem Language Result Execution time Memory
387389 2021-04-08T10:20:02 Z stefantaga Type Printer (IOI08_printer) C++14
20 / 100
93 ms 39012 KB
#include <bits/stdc++.h>

using namespace std;
struct trie
{
    int nr,marime;
    trie *v[28];
    trie ()
    {
        int j;
        nr=0;
        marime=0;
        for (j=0;j<=26;j++)
        {
            v[j]=nullptr;
        }
    }
} *tree = new trie ;
void adauga (trie *tree, char *s)
{
    if (*s==0)
    {
        tree->nr++;
        return;
    }
    int loc=(*s-'a');
    if (tree->v[loc]==nullptr)
    {
        tree->v[loc]=new trie;
    }
    adauga(tree->v[loc],s+1);
}
vector <char> op;
void dfs1(trie *tree)
{
    int j;
    tree->marime=1+tree->nr;
    for (j=0;j<=26;j++)
    {
        if (tree->v[j]!=nullptr)
        {
            dfs1(tree->v[j]);
            tree->marime=tree->marime+tree->v[j]->marime;
        }
    }
}
void dfs2(trie *tree)
{
    int j;
    vector <pair <int,int> > val;
    for (j=0;j<=26;j++)
    {
        if (tree->v[j]!=nullptr)
        {
            val.push_back({tree->v[j]->marime,j});
        }
    }
    sort (val.begin(),val.end());
    for (j=0;j<val.size();j++)
    {
        op.push_back((char)(val[j].second+97));
        dfs2(tree->v[val[j].second]);
        op.push_back('-');
    }
    for (j=1;j<=tree->nr;j++)
    {
        op.push_back('P');
    }
}
int n,i,j;
char s[25];
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(0);
    #ifdef HOME
    ifstream cin("date.in");
    ofstream cout("date.out");
    #endif // HOME
    cin>>n;

    for (i=1;i<=n;i++)
    {
        cin>>s;
        adauga(tree,s);
    }
    dfs1(tree);
    dfs2(tree);
    while (op.size()>0&&op[op.size()-1]=='-')
    {
        op.pop_back();
    }
    cout<<op.size()<<'\n';
    for (j=0;j<op.size();j++)
    {
        cout<<op[j]<<'\n';
    }
    return 0;
}

Compilation message

printer.cpp: In function 'void dfs2(trie*)':
printer.cpp:59:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (j=0;j<val.size();j++)
      |              ~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:94:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (j=0;j<op.size();j++)
      |              ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 6380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 15720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 93 ms 39012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 77 ms 30436 KB Output isn't correct
2 Halted 0 ms 0 KB -