Submission #878378

#TimeUsernameProblemLanguageResultExecution timeMemory
878378vjudge1Type Printer (IOI08_printer)C++14
100 / 100
105 ms52760 KiB
#include <iostream> using namespace std; string output; char val[500001]; int m, sz, cnt_print; bool ed[500001], mk[500001]; struct node{ int son[26], cnt; }nd[500001]; inline void add(const string &s){ int cur = 0; for (int i = 0; i < s.size(); i++){ if (!nd[cur].son[s[i] - 'a']){ nd[cur].son[s[i] - 'a'] = ++sz; } val[nd[cur].son[s[i] - 'a']] = s[i]; cur = nd[cur].son[s[i] - 'a']; } ed[cur] = true; } inline void mark(const string &s){ int cur = 0; for (int i = 0; i < s.size(); i++){ mk[nd[cur].son[s[i] - 'a']] = true; cur = nd[cur].son[s[i] - 'a']; } } void dfs(const int &x){ if (ed[x] && x != 0){ cnt_print++; output += 'P'; } if (cnt_print == m){ cout << output.size() << "\n"; for (int i = 0; i < output.size(); i++){ cout << output[i] << "\n"; } return; } int cur = 0; for (int i = 0; i < 26; i++){ cur = nd[x].son[i]; if (!mk[cur] && cur != 0){ output += val[cur]; dfs(cur); output += '-'; } } for (int i = 0; i < 26; i++){ cur = nd[x].son[i]; if (mk[cur] && cur != 0){ output += val[cur]; dfs(cur); output += '-'; } } } int main(){ cin.tie(NULL); ios_base::sync_with_stdio(false); cin >> m; string max_size; for (int i = 1; i <= m; i++){ string s; cin >> s; add(s); if (max_size.size() < s.size()){ max_size = s; } } mark(max_size); dfs(0); return 0; }

Compilation message (stderr)

printer.cpp: In function 'void add(const string&)':
printer.cpp:15:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for (int i = 0; i < s.size(); i++){
      |                     ~~^~~~~~~~~~
printer.cpp: In function 'void mark(const string&)':
printer.cpp:27:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for (int i = 0; i < s.size(); i++){
      |                     ~~^~~~~~~~~~
printer.cpp: In function 'void dfs(const int&)':
printer.cpp:40:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for (int i = 0; i < output.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...