Submission #916943

# Submission time Handle Problem Language Result Execution time Memory
916943 2024-01-26T20:06:35 Z SonicML Type Printer (IOI08_printer) C++14
40 / 100
37 ms 18672 KB
#include <iostream>
#include <fstream>

using namespace std;

int n, gSize;

int const NMAX = 5e5;
int g[1 + NMAX]['z' - 'a' + 1];
int finish[1 + NMAX];

int printed = 0;

string big = "";
string ans = "";

void DFS(int node, int depth) {
  for(int i = 1;i <= finish[node];i++) {
    ans.push_back('P');
    printed++;
  }
  for(char c = 'a';c <= 'z';c++) {
    int to = g[node][c - 'a'];
    if(to && (c != big[depth])) {
      ans.push_back(c);
      DFS(to, depth+1);
      if(printed < n) {
        ans.push_back('-');
      }
    }
  }
  if(g[node][big[depth] - 'a']) {
    int to = g[node][big[depth] - 'a'];
    ans.push_back(big[depth]);
    DFS(to, depth+1);
    if(printed < n) {
      ans.push_back('-');
    }
  }

}

int main() {

  cin >> n;
  string s;
  for(int i = 1;i <= n;i++) {
    cin >> s;
    int node = 0;
    for(int pos = 0;pos < s.size();pos++) {
      if(g[node][s[pos] - 'a'] == 0) {
        gSize++;
        g[node][s[pos] - 'a'] = gSize;
      }
      node = g[node][s[pos] - 'a'];
    }
    if(big.size() < s.size()) {
      big = s;
    }
    finish[node]++;
  }
  //cerr << big << '\n';
  DFS(0, 0);
  cout << ans.size() << '\n';
  for(int i = 0;i < ans.size();i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:50:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for(int pos = 0;pos < s.size();pos++) {
      |                     ~~~~^~~~~~~~~~
printer.cpp:65:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |   for(int i = 0;i < ans.size();i++) {
      |                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 2 ms 860 KB Line "
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1112 KB Output is correct
2 Correct 3 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3164 KB Output is correct
2 Incorrect 12 ms 6492 KB Line "
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 7660 KB Output is correct
2 Incorrect 8 ms 1884 KB Line "
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 18672 KB Line "
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 14572 KB Line "
2 Halted 0 ms 0 KB -