Submission #685616

#TimeUsernameProblemLanguageResultExecution timeMemory
685616d4xnType Printer (IOI08_printer)C++17
0 / 100
49 ms21636 KiB
#pragma GCC optimize ("Ofast") #include <bits/stdc++.h> using namespace std; struct node { map<int, node*> adj; bool fin; }; int n; string sMx; vector<char> ans; void add(node* root, string s, int idx) { if (idx == s.size()) { root->fin = 1; return; } int x = s[idx] - 'a'; auto it = root->adj.find(x); if (it == root->adj.end()) { root->adj[x] = new node; it = root->adj.find(x); } add(it->second, s, idx+1); } void dfs(node* root, int idx, bool isMx) { if (root->fin) { ans.push_back('P'); } int mx = -1; for (auto& [i, v] : root->adj) { char x = 'a' + i; if (isMx && sMx[idx] == x) { mx = i; continue; } ans.push_back(x); dfs(v, idx+1, 0); ans.push_back('-'); } if (mx != -1) { auto it = root->adj.find(mx); char x = 'a' + mx; ans.push_back(x); dfs(it->second, idx+1, 1); ans.push_back('-'); } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; node* root = new node; int mx = 0; for (int i = 0; i < n; i++) { string s; cin >> s; if (s.size() > mx) { mx = s.size(); sMx = s; } add(root, s, 0); } dfs(root, 0, 1); int r = ans.size()-1; while (ans[r] == '-') r--; for (int i = 0; i <= r; i++) { cout << ans[i] << "\n"; } }

Compilation message (stderr)

printer.cpp: In function 'void add(node*, std::string, int)':
printer.cpp:15:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |   if (idx == s.size()) {
      |       ~~~~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:63:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |     if (s.size() > mx) {
      |         ~~~~~~~~~^~~~
#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...