Submission #396645

#TimeUsernameProblemLanguageResultExecution timeMemory
396645peuchType Printer (IOI08_printer)C++17
10 / 100
82 ms41868 KiB
#include<bits/stdc++.h> using namespace std; const int MAXN = 25000; int n; vector<int> ar[MAXN * 26]; int marc[MAXN * 26]; int letras[MAXN * 26][30]; char v[MAXN * 26]; int cnt = 0; vector<string> palavras; vector<char> ans; void dfs(int cur, int pai){ if(marc[cur]) ans.push_back('P'); for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(viz == pai) continue; ans.push_back(v[viz]); dfs(viz, cur); ans.push_back('-'); } } bool cmp(string a, string b){ return a.size() < b.size(); } int main(){ scanf("%d", &n); for(int i = 0; i < n; i++){ string aux; cin >> aux; palavras.push_back(aux); } sort(palavras.begin(), palavras.end(), cmp); for(int i = 0; i < n; i++){ int cur = 0; for(int j = 0; j < palavras[i].size(); j++){ if(letras[cur][palavras[i][j] - 'a'] == 0) { letras[cur][palavras[i][j] - 'a'] = ++cnt; ar[cur].push_back(cnt); v[cnt] = palavras[i][j]; } cur = letras[cur][palavras[i][j] - 'a']; } marc[cur] = 1; } dfs(0, 0); while(ans[ans.size() - 1] == '-') ans.pop_back(); printf("%d\n", ans.size()); for(int i = 0; i < ans.size(); i++) printf("%c\n", ans[i]); }

Compilation message (stderr)

printer.cpp: In function 'void dfs(int, int)':
printer.cpp:20:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |  for(int i = 0; i < ar[cur].size(); i++){
      |                 ~~^~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |   for(int j = 0; j < palavras[i].size(); j++){
      |                  ~~^~~~~~~~~~~~~~~~~~~~
printer.cpp:55:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wformat=]
   55 |  printf("%d\n", ans.size());
      |          ~^     ~~~~~~~~~~
      |           |             |
      |           int           std::vector<char>::size_type {aka long unsigned int}
      |          %ld
printer.cpp:56:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for(int i = 0; i < ans.size(); i++)
      |                 ~~^~~~~~~~~~~~
printer.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
#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...