Submission #720350

#TimeUsernameProblemLanguageResultExecution timeMemory
720350yellowtoadType Printer (IOI08_printer)C++17
90 / 100
1075 ms41796 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; int n, cnt, b[1000000]; char a[1000000]; string s; vector<pair<int,int>> trie[1000000]; vector<char> ans; int dfs(int u, int depth) { int maxx = depth; for (int i = 0; i < trie[u].size(); i++) { trie[u][i].first = dfs(trie[u][i].second,depth+1); maxx = max(maxx,trie[u][i].first); } sort(trie[u].begin(),trie[u].end()); return maxx; } void dfs1(int u) { for (int i = 1; i <= b[u]; i++) ans.push_back('P'); for (int i = 0; i < trie[u].size(); i++) { ans.push_back(a[trie[u][i].second]); dfs1(trie[u][i].second); ans.push_back('-'); } } int main() { cin >> n; a[++cnt] = ' '; for (int i = 1; i <= n; i++) { cin >> s; int u = 1; for (int j = 0; j < s.length(); j++) { for (int k = 0; k < trie[u].size(); k++) { if (a[trie[u][k].second] == s[j]) { u = trie[u][k].second; goto skip; } } a[++cnt] = s[j]; trie[u].push_back({0,cnt}); u = cnt; skip:; } b[u]++; } dfs(1,0); dfs1(1); while (ans.back() == '-') ans.pop_back(); cout << ans.size() << endl; for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl; }

Compilation message (stderr)

printer.cpp: In function 'int dfs(int, int)':
printer.cpp:14:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |  for (int i = 0; i < trie[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'void dfs1(int)':
printer.cpp:24:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  for (int i = 0; i < trie[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for (int j = 0; j < s.length(); j++) {
      |                   ~~^~~~~~~~~~~~
printer.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for (int k = 0; k < trie[u].size(); k++) {
      |                    ~~^~~~~~~~~~~~~~~~
printer.cpp:55:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |  for (int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
      |                  ~~^~~~~~~~~~~~
#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...