답안 #1063700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063700 2024-08-17T23:44:45 Z dyogorb Type Printer (IOI08_printer) C++14
100 / 100
922 ms 48592 KB
#include <bits/stdc++.h>

using namespace std;
const int WMAX = 1e6;

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

string biggest;
string ans;

void insert(string word){
    int node = 0;

    for (int i = 0; i < word.size(); i++)
    {
        char c = word[i];
        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){    
    if(stop[node]) ans += 'P';
    for (int i = 0; i < 26; i++)
    {
        if((i != biggest[depth] - 'a' || !flag) && trie[node][i]){
            char c = 'a' + i;
            ans += c; 
            dfs(trie[node][i], depth + 1, 0);
            ans += '-';    
        }
    }    
        
    if(depth < biggest.size() && trie[node][biggest[depth] - 'a'] && flag){        
        ans += biggest[depth];        
        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

printer.cpp: In function 'void insert(std::string)':
printer.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < word.size(); i++)
      |                     ~~^~~~~~~~~~~~~
printer.cpp: In function 'void dfs(int, int, int)':
printer.cpp:39:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     if(depth < biggest.size() && trie[node][biggest[depth] - 'a'] && flag){
      |        ~~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 8 ms 844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 1112 KB Output is correct
2 Correct 18 ms 1400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 3156 KB Output is correct
2 Correct 125 ms 6224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 7344 KB Output is correct
2 Correct 44 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 17924 KB Output is correct
2 Correct 759 ms 40972 KB Output is correct
3 Correct 417 ms 21484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 14060 KB Output is correct
2 Correct 922 ms 48592 KB Output is correct
3 Correct 461 ms 24292 KB Output is correct
4 Correct 866 ms 45832 KB Output is correct