답안 #541537

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541537 2022-03-23T18:06:26 Z mateigg4 Type Printer (IOI08_printer) C++14
100 / 100
153 ms 106316 KB
#include <iostream>

using namespace std;

int aux, p = 0;
char sol[1000000];
string s, lw;
struct trie
{
    int printez, sterg, printezlit;
    trie* fii[27];
    trie()
    {
        printez = sterg = printezlit = 0;
        for (aux = 0; aux <= 26; aux++)
            fii[aux] = 0;
    };
};
trie* t = new trie;
void add (trie* x, int poz, int pmax)
{
    if (poz <= pmax)
    {
        x->printezlit = 1, x->sterg = 1;
        int ch = s[poz] - 'a';
        if (x->fii[ch] == 0)
            x->fii[ch] = new trie;
        add (x->fii[ch], poz + 1, pmax);
    }
    else
        x->printez++, x->sterg = 1, x->printezlit = 1;
}
void dfs (trie* x, int poz, int pmax, int ok, char lit)
{
    int i, xp = x->printez;
    sol[++p] = lit;
    while (xp--)
        sol[++p] = 'P';
    for (i = 0; i <= 26; i++)
        if (x->fii[i] != 0 && (i + 'a' != lw[poz] || poz > pmax || ok == 0))
            dfs (x->fii[i], poz, pmax, 0, i + 'a');
    if (ok == 1 && poz <= pmax)
        dfs (x->fii[lw[poz] - 'a'], poz + 1, pmax, 1, lw[poz]);
    xp = x->sterg;
    sol[++p] = '-';
}

int main()
{
    int n, i, lm = 0;
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> s;
        add (t, 0, s.size() - 1);
        if (lm < s.size())
            lm = s.size(), lw = s;
    }
    dfs (t, 0, lw.size() - 1, 1, ' ');
    while (sol[p] == '-')
        p--;
    cout << p - 1 << '\n';
    for (i = 2; i <= p; i++)
        cout << sol[i] << '\n';
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:56:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |         if (lm < s.size())
      |             ~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 308 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1852 KB Output is correct
2 Correct 4 ms 2360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6304 KB Output is correct
2 Correct 19 ms 13232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 15632 KB Output is correct
2 Correct 11 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 38972 KB Output is correct
2 Correct 124 ms 89356 KB Output is correct
3 Correct 73 ms 45936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 30460 KB Output is correct
2 Correct 153 ms 106316 KB Output is correct
3 Correct 84 ms 52172 KB Output is correct
4 Correct 137 ms 100300 KB Output is correct