답안 #511481

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
511481 2022-01-16T00:12:23 Z Yazan_Alattar Type Printer (IOI08_printer) C++14
20 / 100
42 ms 22924 KB
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <utility>
#include <cmath>
#include <numeric>
#include <assert.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x) x.begin(), x.end()
const int M = 200007;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

vector <char> ans;
int n;

struct Trie{
    int to[M][26] = {0}, mx[M] = {0}, sz;
    bool leaf[M] = {0};

    void add(string s){
        int cur = 0;
        mx[0] = max(mx[0], (int)s.size());
        for(int i = 0; i < s.size(); ++i){
            int c = s[i] - 'a';
            if(!to[cur][c]) to[cur][c] = ++sz;
            cur = to[cur][c];
            mx[cur] = max(mx[cur], (int)s.size());
        }
        leaf[cur] = 1;
        return;
    }

    void get(int node){
        vector < pair < pair <int,int>, int > > v;
        for(int i = 0; i < 26; ++i) if(to[node][i]) v.pb({{mx[to[node][i]], i}, to[node][i]});
        sort(all(v));
        for(auto i : v){
            ans.pb(char('a' + i.F.S));
            get(i.S);
        }
        if(leaf[node]) ans.pb('P');
        ans.pb('-');
    }

}T;

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; ++i){
        string s;
        cin >> s;
        T.add(s);
    }
    T.get(0);
    while(ans.back() == '-') ans.pop_back();
    cout << ans.size() << endl;
    for(auto i : ans) cout << i << endl;
    return 0;
}

Compilation message

printer.cpp: In member function 'void Trie::add(std::string)':
printer.cpp:37:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int i = 0; i < s.size(); ++i){
      |                        ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 21580 KB Output is correct
2 Correct 9 ms 21572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 21628 KB Output is correct
2 Correct 9 ms 21580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 11 ms 21648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 21528 KB Output is correct
2 Incorrect 9 ms 21580 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 21580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 21708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 21828 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 22276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 22924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 36 ms 22748 KB Output isn't correct
2 Halted 0 ms 0 KB -