Submission #387362

# Submission time Handle Problem Language Result Execution time Memory
387362 2021-04-08T09:58:11 Z stefantaga Type Printer (IOI08_printer) C++14
30 / 100
198 ms 89568 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;
    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;
    for (j=1;j<=tree->nr;j++)
    {
        op.push_back('P');
    }
    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('-');
    }
}
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:63: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]
   63 |     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 Correct 1 ms 364 KB Output is 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 Correct 4 ms 2028 KB Output is correct
2 Incorrect 6 ms 2412 KB Output isn't correct
# 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 37 ms 15788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 39268 KB Output is correct
2 Correct 198 ms 89568 KB Output is correct
3 Incorrect 97 ms 46180 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 30692 KB Output isn't correct
2 Halted 0 ms 0 KB -