답안 #592017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
592017 2022-07-08T11:40:07 Z Do_you_copy Type Printer (IOI08_printer) C++17
40 / 100
62 ms 96780 KB
#include <bits/stdc++.h>
#define taskname "test"
#define fi first
#define se second
#define pb push_back
#define faster ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pil = pair <int, ll>;
using pli = pair <ll, int>;
using pll = pair <ll, ll>;
using ull = unsigned ll;
mt19937 Rand(chrono::steady_clock::now().time_since_epoch().count());

ll min(const ll &a, const ll &b){
    return (a < b) ? a : b;
}

ll max(const ll &a, const ll &b){
    return (a > b) ? a : b;
}

//const ll Mod = 1000000009;
//const ll Mod2 = 999999999989;
//only use when required
const int maxN = 1e5 + 1;

int n;
string s;
struct TTrie{
    TTrie* adj[26];
    TTrie(){
        for (int i = 0; i <= 25; ++i) adj[i] = nullptr;
    }
    bool p = 0;
    int max_depth = 0;
};

TTrie* root = new TTrie();

void add(TTrie* id, int i = 0, int m = s.length()){
    if (i == m){
        id->p = 1;
        id->max_depth = max(id->max_depth, m);
        return;
    }
    if (!id->adj[s[i] - 'a']) id->adj[s[i] - 'a'] = new TTrie();
    add(id->adj[s[i] - 'a'], i + 1, m);
    id->max_depth = max(id->max_depth, m);
}

vector <char> v;
void dfs(TTrie* id = root){
    TTrie* tem = nullptr;
    int p = 0;
    if (id->p) v.pb('P');
    for (int i = 0; i <= 25; ++i){
        if (id->adj[i]){
            if (id->adj[i]->max_depth == root->max_depth){
                tem = id->adj[i];
                p = i;
                continue;
            }
            v.pb(i + 'a');
            dfs(id->adj[i]);
            v.pb('-');
        }
    }
    if (tem){
        v.pb(p + 'a');
        dfs(tem);
    }
}

void Init(){
    cin >> n;
    for (int i = 1; i <= n; ++i){
        cin >> s;
        add(root);
    }
    dfs();
    cout << v.size() << "\n";
    for (char c: v) cout << c << "\n";
}

int main(){
    if (fopen(taskname".inp", "r")){
        freopen(taskname".inp", "r", stdin);
        //freopen(taskname".out", "w", stdout);
    }
    faster;
    ll tt = 1;
    //cin >> tt;
    while (tt--){
        Init();
    }
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 212 KB didn't print every word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 1108 KB didn't print every word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1748 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 5968 KB Output is correct
2 Incorrect 10 ms 12116 KB didn't print every word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 14780 KB Output is correct
2 Incorrect 5 ms 3156 KB didn't print every word
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 21 ms 35592 KB didn't print every word
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 28716 KB Output is correct
2 Incorrect 62 ms 96780 KB didn't print every word
3 Halted 0 ms 0 KB -