Submission #439446

# Submission time Handle Problem Language Result Execution time Memory
439446 2021-06-30T03:00:24 Z ldn694 Type Printer (IOI08_printer) C++17
0 / 100
42 ms 19028 KB
#include <bits/stdc++.h>
#define fu(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
using namespace std;
const int N = 25e3 + 10;
const int M = 5e5 + 10;
int n;
string a[N];
int trie[M][27], sz = 0;
bool tail[M];
string longest;
void Insert(const string &a)
{
    int node = 0;
    for (char c : a)
    {
        int x = int(c) - 96;
        if (!trie[node][x]) trie[node][x] = ++sz;
        node = trie[node][x];
    }
    tail[node] = true;
}
void DFS(int u, int depth, bool still)
{
    int c = int(longest[depth]) - 96;
//    cout << u << " " << depth << "\n";
    fu(i, 1, 26)
    {
        if (trie[u][i] == 0) continue;
        if (i == c  && still) continue;
        cout << char(i + 96) << "\n";
        if (tail[trie[u][i]]) cout << "P\n";
        DFS(trie[u][i], depth + 1, false);
        cout << "-\n";
    }
    if (still)
    {
        cout << longest[depth] << "\n";
        if (depth < (int)longest.size() - 1 && trie[u][c]) DFS(trie[u][c], depth + 1, still); else cout << "P";
    }
}
int main()
{
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin >> n;
    fu(i, 1, n)
    {
        cin >> a[i];
    }
    fu(i, 1, n)
    {
        Insert(a[i]);
    }
    longest = a[1];
    fu(i, 2, n)
    {
        if (longest.size() < a[i].size()) longest = a[i];
    }
    cout << sz * 2 - 2 << "\n";
    DFS(0, 0, 1);
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 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 1 ms 1100 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 1 ms 1100 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 1 ms 1100 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 1100 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1868 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 3824 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 8140 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 19028 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 14800 KB Expected EOF
2 Halted 0 ms 0 KB -