Submission #989160

# Submission time Handle Problem Language Result Execution time Memory
989160 2024-05-27T16:09:38 Z aykhn Type Printer (IOI08_printer) C++17
0 / 100
32 ms 38184 KB
#include <bits/stdc++.h>
 
using namespace std;

const int MXN = 25000 * 20 + 5;

int n, m;
int node[MXN][26], cnt[MXN];
vector<int> adj[MXN];
char val[MXN];
int mx[MXN], cur;
vector<char> moves;

void add(int a, int i, string &s)
{
    if (i == s.length())
    {
        cnt[a]++;
        mx[a] = s.length();
        return;
    }
    if (!node[a][s[i] - 'a']) node[a][s[i] - 'a'] = ++m, adj[a].push_back(m), val[m] = s[i];
    add(node[a][s[i] - 'a'], i + 1, s);
    mx[a] = max(mx[a], mx[node[a][s[i] - 'a']]);
}
void dfs(int a)
{
    moves.push_back(val[a]);
    for (int i = 0; i < cnt[a]; i++) moves.push_back('P'), cur++;
    for (int v : adj[a]) dfs(v);
    if (cur != n) moves.push_back('-');
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    string s[n];
    for (string &i : s) cin >> i, add(0, 0, i);
    for (int i = 0; i <= m; i++)
    {
        sort(adj[i].begin(), adj[i].end(), [&](const int &a, const int &b)
        {
            return mx[a] < mx[b];
        });
    }
    dfs(0);
    cout << moves.size() << '\n';
    for (char &ch : moves) cout << ch << '\n';
}

Compilation message

printer.cpp: In function 'void add(int, int, std::string&)':
printer.cpp:16:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     if (i == s.length())
      |         ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14684 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 14684 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14684 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14684 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14684 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 15708 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 18524 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 24024 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 38184 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 32968 KB Line "
2 Halted 0 ms 0 KB -