Submission #674029

#TimeUsernameProblemLanguageResultExecution timeMemory
674029peacebringer1667Type Printer (IOI08_printer)C++17
40 / 100
1095 ms16724 KiB
#include<bits/stdc++.h> #define whilst while typedef long long ll; using namespace std; string a[25003]; int f[650078][27]; int b[25003]; int m = 0;bool eow[650078]; vector <vector<int>> vec(650078); void dfs(int u){ cout << (char)f[u][0] << endl; if (eow[u]) cout << "P" << endl; for (int i = 0 ; i < vec[u].size() ; i++) dfs(vec[u][i]); cout << "-" << endl; } void dfs2(int u){ cout << (char)f[u][0] << endl; if (eow[u]) cout << "P" << endl; for (int i = 0 ; i < vec[u].size() ; i++) dfs2(vec[u][i]); if (m == -1) return; else if (u == m){ m = -1; return; } else cout << "-" << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0); int d1 = 0,n,cur,j,maxlen = 0,index = n;string x;char t; cin >> n; for (int i = 1 ; i <= n ; i++){ cin >> a[i]; if (maxlen < a[i].size()){ maxlen = a[i].size();index = i; } } swap(a[index],a[n]);t = a[n][0]; for (int i = 1 ; i < n; i++) if (a[i][0] != t){ cur = 0,j = 0; while (j < a[i].size() && f[cur][a[i][j]-96]){ cur = f[cur][a[i][j]-96];j++; } if (j == a[i].size()){ j = 0; while (j < a[i].size()-1) cur = f[cur][a[i][j]-96];j++; eow[cur] = 1; } else for (int k = j ; k < a[i].size() ; k++){ m++;f[cur][a[i][k]-96] = m;f[m][0] = a[i][k];vec[cur].push_back(m); cur = m; } eow[m] = 1; } for (int i = 1 ; i <= n ; i++) if (a[i][0] == t){ cur = 0,j = 0; while (j < a[i].size() && f[cur][a[i][j]-96]){ cur = f[cur][a[i][j]-96];j++; } if (j == a[i].size()){ j = 0; while (j < a[i].size()-1) cur = f[cur][a[i][j]-96];j++; eow[cur] = 1; } else for (int k = j ; k < a[i].size() ; k++){ m++;f[cur][a[i][k]-96] = m;f[m][0] = a[i][k];vec[cur].push_back(m); cur = m; } eow[m] = 1; } cout << 2*m - a[n].size() + n << endl; for (int i = 0 ; i < vec[0].size()-1 ; i++) dfs(vec[0][i]); dfs2(vec[0][vec[0].size()-1]); return 0; }

Compilation message (stderr)

printer.cpp: In function 'void dfs(int)':
printer.cpp:13:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for (int i = 0 ; i < vec[u].size() ; i++)
      |                   ~~^~~~~~~~~~~~~~~
printer.cpp: In function 'void dfs2(int)':
printer.cpp:20:21: 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 < vec[u].size() ; i++)
      |                   ~~^~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:37:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |      if (maxlen < a[i].size()){
      |          ~~~~~~~^~~~~~~~~~~~~
printer.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |         while (j < a[i].size() && f[cur][a[i][j]-96]){
      |                ~~^~~~~~~~~~~~~
printer.cpp:48:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |   if (j == a[i].size()){
      |       ~~^~~~~~~~~~~~~~
printer.cpp:50:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |    while (j < a[i].size()-1)
      |           ~~^~~~~~~~~~~~~~~
printer.cpp:50:4: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   50 |    while (j < a[i].size()-1)
      |    ^~~~~
printer.cpp:51:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   51 |      cur = f[cur][a[i][j]-96];j++;
      |                               ^
printer.cpp:54:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |   else for (int k = j ; k < a[i].size() ; k++){
      |                         ~~^~~~~~~~~~~~~
printer.cpp:62:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         while (j < a[i].size() && f[cur][a[i][j]-96]){
      |                ~~^~~~~~~~~~~~~
printer.cpp:65:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   if (j == a[i].size()){
      |       ~~^~~~~~~~~~~~~~
printer.cpp:67:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |    while (j < a[i].size()-1)
      |           ~~^~~~~~~~~~~~~~~
printer.cpp:67:4: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   67 |    while (j < a[i].size()-1)
      |    ^~~~~
printer.cpp:68:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   68 |      cur = f[cur][a[i][j]-96];j++;
      |                               ^
printer.cpp:72:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for (int k = j ; k < a[i].size() ; k++){
      |                    ~~^~~~~~~~~~~~~
printer.cpp:79:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |  for (int i = 0 ; i < vec[0].size()-1 ; i++) dfs(vec[0][i]);
      |                   ~~^~~~~~~~~~~~~~~~~
printer.cpp:33:9: warning: unused variable 'd1' [-Wunused-variable]
   33 |     int d1 = 0,n,cur,j,maxlen = 0,index = n;string x;char t;
      |         ^~
#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...