Submission #916949

# Submission time Handle Problem Language Result Execution time Memory
916949 2024-01-26T20:14:21 Z SonicML Type Printer (IOI08_printer) C++14
100 / 100
104 ms 49936 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 && (depth >= big.size() || c != big[depth])) {
      ans.push_back(c);
      DFS(to, depth+1);
      if(printed < n) {
        ans.push_back('-');
      }
    }
  }
  if(depth < big.size() && 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 'void DFS(int, int)':
printer.cpp:24:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     if(to && (depth >= big.size() || c != big[depth])) {
      |               ~~~~~~^~~~~~~~~~~~~
printer.cpp:32:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   if(depth < big.size() && g[node][big[depth] - 'a']) {
      |      ~~~~~~^~~~~~~~~~~~
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 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 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 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1116 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 Correct 12 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 7660 KB Output is correct
2 Correct 9 ms 1884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 18416 KB Output is correct
2 Correct 104 ms 42000 KB Output is correct
3 Correct 58 ms 22004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 14328 KB Output is correct
2 Correct 102 ms 49936 KB Output is correct
3 Correct 65 ms 24772 KB Output is correct
4 Correct 84 ms 47120 KB Output is correct