Submission #916949

#TimeUsernameProblemLanguageResultExecution timeMemory
916949SonicMLType Printer (IOI08_printer)C++14
100 / 100
104 ms49936 KiB
#include <iostream> #include <fstream> using namespace std; int n, gSize; int const NMAX = 5e5; int g[1 + NMAX]['z' - 'a' + 1]; int finish[1 + NMAX]; int printed = 0; string big = ""; string ans = ""; void DFS(int node, int depth) { for(int i = 1;i <= finish[node];i++) { ans.push_back('P'); printed++; } for(char c = 'a';c <= 'z';c++) { int to = g[node][c - 'a']; if(to && (depth >= big.size() || c != big[depth])) { ans.push_back(c); DFS(to, depth+1); if(printed < n) { ans.push_back('-'); } } } if(depth < big.size() && g[node][big[depth] - 'a']) { int to = g[node][big[depth] - 'a']; ans.push_back(big[depth]); DFS(to, depth+1); if(printed < n) { ans.push_back('-'); } } } int main() { cin >> n; string s; for(int i = 1;i <= n;i++) { cin >> s; int node = 0; for(int pos = 0;pos < s.size();pos++) { if(g[node][s[pos] - 'a'] == 0) { gSize++; g[node][s[pos] - 'a'] = gSize; } node = g[node][s[pos] - 'a']; } if(big.size() < s.size()) { big = s; } finish[node]++; } //cerr << big << '\n'; DFS(0, 0); cout << ans.size() << '\n'; for(int i = 0;i < ans.size();i++) { cout << ans[i] << '\n'; } return 0; }

Compilation message (stderr)

printer.cpp: In function 'void DFS(int, int)':
printer.cpp:24:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     if(to && (depth >= big.size() || c != big[depth])) {
      |               ~~~~~~^~~~~~~~~~~~~
printer.cpp:32:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   if(depth < big.size() && g[node][big[depth] - 'a']) {
      |      ~~~~~~^~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:50:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int pos = 0;pos < s.size();pos++) {
      |                     ~~~~^~~~~~~~~~
printer.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i = 0;i < ans.size();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...