Submission #212279

#TimeUsernameProblemLanguageResultExecution timeMemory
212279jk89Type Printer (IOI08_printer)C++14
100 / 100
109 ms48628 KiB
#include <iostream> #include <cstring> #include <vector> using namespace std; const int MAXN = 5e5 + 3; const int ALF = 26; int t[MAXN][ALF]; bool mask[MAXN]; vector<char> odp; void DFS(int x) { if (mask[x]) odp.push_back('P'); for (int i = 0; i < ALF; i++) { if (t[x][i] != 0) { odp.push_back(char(i + 'a')); DFS(t[x][i]); } } odp.push_back('-'); } int main() { ios_base::sync_with_stdio(false); int n; string s, temp; cin >> n; int ind = 0; int akt, x; int mx = 0; for (int i = 1; i <= n; i++) { cin >> s; if (s.size() > mx) { mx = s.size(); temp = s; } akt = 0; for (int j = 0; j < s.size(); j++) { x = s[j] - 'a'; if (t[akt][x] != 0) akt = t[akt][x]; else { ind++; t[akt][x] = ind; akt = ind; } } mask[akt] = true; } akt = 0; for (int i = 0; i < mx; i++) { for (int j = 0; j < ALF; j++) { if (t[akt][j] != 0 && j != temp[i] - 'a') { odp.push_back(char(j + 'a')); DFS(t[akt][j]); } } akt = t[akt][temp[i] - 'a']; odp.push_back(temp[i]); if (mask[akt]) odp.push_back('P'); } cout << odp.size() << '\n'; for (auto it:odp) cout << it << '\n'; return 0; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:35:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (s.size() > mx) {
             ~~~~~~~~~^~~~
printer.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < s.size(); j++) {
                         ~~^~~~~~~~~~
#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...