Submission #989161

#TimeUsernameProblemLanguageResultExecution timeMemory
989161aykhnType Printer (IOI08_printer)C++17
0 / 100
37 ms37836 KiB
#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(); for (char &ch : moves) cout << '\n' << ch; }

Compilation message (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...