Submission #1063692

# Submission time Handle Problem Language Result Execution time Memory
1063692 2024-08-17T23:34:56 Z dyogorb Type Printer (IOI08_printer) C++14
0 / 100
7 ms 6748 KB
#include <bits/stdc++.h>

using namespace std;
const int WMAX = 3e4;

int trie[WMAX][26];
int node_count;
bool stop[WMAX];

string biggest;
string ans;

void insert(string word){
    int node = 0;
    for (char c: word)
    {
        if(trie[node][c - 'a'] == 0) trie[node][c - 'a'] = ++node_count;
        
        node = trie[node][c - 'a'];
    }    
    stop[node] = true;
}

void dfs(int node, int depth, int flag){
    for (int i = 0; i < 26; i++)
    {
        if((i != biggest[depth] - 'a' || !flag) && trie[node][i]){
            char c = 'a' + i;
            ans += c; 
            if(stop[trie[node][i]]) ans += 'P';
            dfs(trie[node][i], depth + 1, 0);
            ans += '-';    
        }
    }

    assert(depth < biggest.size());
        
    if(trie[node][biggest[depth] - 'a'] && flag){        
        ans += biggest[depth];
        if(depth == biggest.size() - 1) ans += 'P';
        dfs(trie[node][biggest[depth] - 'a'], depth + 1, 1);                
    }
    
}

int main(){
    int n;
    cin >> n;
    string s;
    biggest = "";

    for (int i = 0; i < n; i++)
    {
        cin >> s;     
        insert(s);   
        if(s.size() > biggest.size()) biggest = s;
    }
    
    dfs(0, 0, 1);
    cout << ans.size() << endl;
    for (auto c : ans)
    {
        cout << c << endl;
    }
    
}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from printer.cpp:1:
printer.cpp: In function 'void dfs(int, int, int)':
printer.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     assert(depth < biggest.size());
      |            ~~~~~~^~~~~~~~~~~~~~~~
printer.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         if(depth == biggest.size() - 1) ans += 'P';
      |            ~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1884 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5980 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 6748 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 6744 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 6748 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -