Submission #592022

# Submission time Handle Problem Language Result Execution time Memory
592022 2022-07-08T11:47:08 Z Do_you_copy Type Printer (IOI08_printer) C++17
50 / 100
108 ms 97908 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 = -1;
    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;
            }
        }
    }
    for (int i = 0; i <= 25; ++i){
        if (id->adj[i]){
            if (i == p) 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:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(taskname".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 2 ms 1108 KB printed invalid word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1748 KB Output is correct
2 Correct 3 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 5884 KB Output is correct
2 Incorrect 17 ms 12500 KB printed invalid word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 14700 KB Output is correct
2 Incorrect 7 ms 3156 KB printed invalid word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 36356 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 28404 KB Output is correct
2 Incorrect 108 ms 97908 KB printed invalid word
3 Halted 0 ms 0 KB -