Submission #418001

# Submission time Handle Problem Language Result Execution time Memory
418001 2021-06-04T20:22:02 Z iulia13 Type Printer (IOI08_printer) C++14
20 / 100
88 ms 39100 KB
#include <iostream>
#include <cstring>
using namespace std;
const int L = 26;
struct nod
{
    int cnt, sons, marked;
    nod *son[L];
    nod()
    {
        cnt = sons = marked = 0;
        for (int i = 0; i < L; i++)
            son[i] = 0;
    }
};
int ans = 0;
nod *trie = new nod;
void update(nod *trie, char *s, int val, int lit, int tip)
{
    int next;
    trie->marked += tip;
    if (!lit)
    {
        trie->cnt += val;
        return;
    }
    if (trie->son[*s - 'a'] == 0)
    {
        trie->son[*s - 'a'] = new nod;
        trie->sons++;
    }
    update((trie->son[*s - 'a']), s + 1, val, lit - 1, tip);
}
int stop = 0;
void dfs(nod *trie)
{
    if (trie->sons == 0)
    {
        cout << "P" << '\n';
        if (trie->marked == 1)
            stop = 1;
        return;
    }
    int dani = -1;
    for (int i = 0; i < L; i++)
    {
        if (trie->son[i] == 0)
            continue;
        if (trie->son[i]->marked == 1)
            dani = i;
        else
        {
            char x = i + 'a';
            cout << x << '\n';
            dfs(trie->son[i]);
            cout << "-" << '\n';
        }
    }
    if (dani == -1)
        return;
    char x = dani + 'a';
    cout << x << '\n';
    dfs(trie->son[dani]);
}
int inc = 0;
void dfs_ans(nod *trie)
{
    if (inc)
        ans += 2 - trie->marked;
    inc++;
    for (int i = 0; i < L; i++)
    {
        if (trie->son[i] == 0)
            continue;
        dfs_ans(trie->son[i]);
    }
}
char s[25005][L];
int main()
{
    int n, i, maxim = -1;
    cin >> n;
    ans = n;
    trie->cnt = 1;
    for (i = 1; i <= n; i++)
    {
        cin >> s[i];
        int aw = strlen(s[i]);
        maxim = max(maxim, aw);
    }
    for (i = 1; i <= n; i++)
    {
        int op = 0, lit = strlen(s[i]);
        if(maxim == lit)
            op = 1, maxim = -1;
        update(trie, s[i], 1, lit, op);
    }
    dfs_ans(trie);
    cout << ans << '\n';
    dfs(trie);
    return 0;
}

Compilation message

printer.cpp: In function 'void update(nod*, char*, int, int, int)':
printer.cpp:21:9: warning: unused variable 'next' [-Wunused-variable]
   21 |     int next;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 204 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1964 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 6220 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 15612 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 88 ms 39100 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 30816 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -