Submission #107465

#TimeUsernameProblemLanguageResultExecution timeMemory
107465tictaccatType Printer (IOI08_printer)C++14
100 / 100
226 ms76392 KiB
#include <bits/stdc++.h> using namespace std; const int MAX = 25000 + 10; int N; vector<string> words; string longest; vector<vector<int>> trie(20*MAX,vector<int>(26)); vector<int> hasString(20*MAX); int c = 0; //current max node in tree ostringstream oss; int ops; void insert (const string &s) { int u = 0; for (int i = 0; i < s.size(); i++) { if (trie[u][s[i]-'a']) u = trie[u][s[i]-'a']; else u = trie[u][s[i]-'a'] = ++c; } hasString[u] = true; } void dfs(int u, int adv) { if (hasString[u]) { ops++; oss << "P\n"; } if (adv == longest.size()) { cout << ops << "\n" << oss.str(); exit(0); } for (int c = 0; c < 26; c++) { if (c == longest[adv]-'a') continue; if (trie[u][c]) { ops++; oss << (char)('a'+c) << "\n"; dfs(trie[u][c],adv); } } if (trie[u][longest[adv]-'a']) { ops++; oss << longest[adv] << "\n"; dfs(trie[u][longest[adv]-'a'],adv+1); } ops++; oss << "-\n"; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) { string w; cin >> w; words.push_back(w); insert(w); } longest = *max_element(words.begin(),words.end(),[](string a, string b) {return a.size() < b.size();}); dfs(0,0); return 0; }

Compilation message (stderr)

printer.cpp: In function 'void insert(const string&)':
printer.cpp:20:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++) {
                     ~~^~~~~~~~~~
printer.cpp: In function 'void dfs(int, int)':
printer.cpp:32:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (adv == longest.size()) {
         ~~~~^~~~~~~~~~~~~~~~~
#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...