Submission #936838

#TimeUsernameProblemLanguageResultExecution timeMemory
936838IrateType Printer (IOI08_printer)C++14
30 / 100
38 ms53008 KiB
#include<bits/stdc++.h> using namespace std; struct Trie{ vector<vector<int>>trie; vector<bool>isWord; int nxt = 1, mxN = 5e5 + 5; string S = ""; Trie(){ trie.resize(26); for(int i = 0;i < 26;++i){ trie[i].resize(mxN); } isWord.resize(mxN); } void Insert(string &s){ int cur = 0; for(int i = 0;i < s.size();++i){ if(trie[s[i] - 'a'][cur]){ cur = trie[s[i] - 'a'][cur]; } else{ trie[s[i] - 'a'][cur] = nxt; cur = nxt; nxt++; } } isWord[cur] = 1; } void Traverse(int cur){ if(isWord[cur]){ S += 'P'; S += '\n'; } for(int i = 0;i < 26;++i){ if(trie[i][cur]){ S += char('a' + i); S += '\n'; Traverse(trie[i][cur]); } } S += '-'; S += '\n'; } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; Trie tr; int mx = 0; string longest = ""; for(int i = 0;i < n;++i){ string s; cin >> s; if(s.size() > mx){ mx = s.size(); longest = s; } tr.Insert(s); } for(int i = 0;i < 26;++i){ if(longest[0] - 'a' == i || !tr.trie[i][0])continue; tr.S += char('a' + i); tr.S += '\n'; tr.Traverse(tr.trie[i][0]); } tr.S += longest[0]; tr.S += '\n'; tr.Traverse(tr.trie[longest[0] - 'a'][0]); while(tr.S.back() == '-' || tr.S.back() == '\n')tr.S.pop_back(); cout << (tr.S.size() + 1) / 2 << "\n" << tr.S; }

Compilation message (stderr)

printer.cpp: In member function 'void Trie::Insert(std::string&)':
printer.cpp:17:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         for(int i = 0;i < s.size();++i){
      |                       ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:56:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |         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...