Submission #109188

#TimeUsernameProblemLanguageResultExecution timeMemory
109188MetBType Printer (IOI08_printer)C++14
100 / 100
256 ms85876 KiB
#include <iostream> #include <cstdlib> #include <string> #include <set> #include <map> #include <algorithm> #include <bitset> #include <queue> #include <math.h> #include <stack> #include <vector> #include <string.h> #include <random> typedef long long ll; const ll MOD = 1e9 + 7, INF = 1e18; using namespace std; int n, ptr, printed; string ans; struct Node { map <char, pair <int, int> > next; bool st; } a[1000000]; void add (string s) { int x = 0; for (int i = 0; i < s.length (); i++) { if (a[x].next.find (s[i]) == a[x].next.end ()) { a[x].next[s[i]] = make_pair (ptr + 1, (int) s.length () - i); ptr++; } if (a[x].next[s[i]].second < (int) s.length () - i) a[x].next[s[i]].second = (int) s.length () - i; x = a[x].next[s[i]].first; } a[x].st = true; } void dfs (int x) { vector < pair <int, char> > v; if (a[x].st) { ans += 'P'; printed++; } for (pair <char, pair <int, int> > it : a[x].next) v.emplace_back (it.second.second, it.first); sort (v.begin(), v.end()); for (auto to : v) { ans += char (to.second); dfs (a[x].next[to.second].first); } if (printed < n) ans += '-'; } int main () { cin >> n; for (int i = 0; i < n; i++) { string s; cin >> s; add (s); } dfs (0); cout << ans.length () << endl; for (auto a : ans) printf ("%c\n", a); }

Compilation message (stderr)

printer.cpp: In function 'void add(std::__cxx11::string)':
printer.cpp:36:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < s.length (); i++)
                  ~~^~~~~~~~~~~~~
#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...