제출 #418007

#제출 시각아이디문제언어결과실행 시간메모리
418007iulia13Type Printer (IOI08_printer)C++14
100 / 100
181 ms107028 KiB
#include <iostream> #include <vector> #include <cstring> using namespace std; const int L = 26; struct nod { int cnt, sons, marked, endofword; nod *son[L]; nod() { cnt = sons = marked = endofword = 0; for (int i = 0; i < L; i++) son[i] = 0; } }; int ans = 0; vector <char> sol; nod *trie = new nod; void update(nod *trie, char *s, int val, int lit, int tip) { int next; trie->marked += tip; if (!lit) { trie->endofword = 1; trie->cnt += val; return; } if (trie->son[*s - 'a'] == 0) { trie->son[*s - 'a'] = new nod; trie->sons++; } update((trie->son[*s - 'a']), s + 1, val, lit - 1, tip); } int stop = 0; void dfs(nod *trie) { if (trie->endofword) sol.push_back('P'); if (trie->sons == 0) { if (trie->marked == 1) stop = 1; return; } int dani = -1; for (int i = 0; i < L; i++) { if (trie->son[i] == 0) continue; if (trie->son[i]->marked == 1) dani = i; else { char x = i + 'a'; sol.push_back(x); /// cout << x << '\n'; dfs(trie->son[i]); sol.push_back('-'); /// cout << "-" << '\n'; } } if (dani == -1) return; char x = dani + 'a'; sol.push_back(x); /// cout << x << '\n'; dfs(trie->son[dani]); } /** 11 hjxgqk ppmqpceairhdont pwfxlmwfirlgbdevjd ppgqvqovp wdmcpctdc wxcfafyveyuj vbjxavqcmxzbfiel xrmqggqby rhpqtslc pw iupqiq **/ char s[25005][L]; int main() { int n, i, maxim = -1; cin >> n; ans = n; trie->cnt = 1; for (i = 1; i <= n; i++) { cin >> s[i]; int aw = strlen(s[i]); maxim = max(maxim, aw); } for (i = 1; i <= n; i++) { int op = 0, lit = strlen(s[i]); if(maxim == lit) op = 1, maxim = -1; update(trie, s[i], 1, lit, op); } dfs(trie); cout << sol.size() << '\n'; for (i = 0; i < sol.size(); i++) cout << sol[i] << '\n'; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

printer.cpp: In function 'void update(nod*, char*, int, int, int)':
printer.cpp:23:9: warning: unused variable 'next' [-Wunused-variable]
   23 |     int next;
      |         ^~~~
printer.cpp: In function 'int main()':
printer.cpp:109:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for (i = 0; i < sol.size(); i++)
      |                 ~~^~~~~~~~~~~~
#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...