Submission #520079

# Submission time Handle Problem Language Result Execution time Memory
520079 2022-01-28T09:51:01 Z HaYoungJoon Type Printer (IOI08_printer) C++14
0 / 100
11 ms 12108 KB
#include <bits/stdc++.h>

using namespace std;

int trie[500001][26],timer = 0;
int n;
vector<int> adj[500001];
bool mark[500001], special[500001];
char label[500001];
vector<char> res;

void addString(string s) {
    int cur = 0;
    for (char c: s) {
        int val = c - 'a';
        if (!trie[cur][val]) {
            trie[cur][val] = ++timer;
            adj[cur].emplace_back(timer);
            label[timer] = c;
        }
        cur = trie[cur][val];
    }
    special[cur] = 1;
}

void markLongest(string s) {
    int cur = 0;
    for (char c: s) {
        int val = c - 'a';
        mark[trie[cur][val]] = 1;
        cur = trie[cur][val];
    }
    mark[cur] = 1;
}


void DFS(int u) {
    int cnt = 0;
    if (special[u]) {
        res.emplace_back('P');
        n--;
    }
    for (int v: adj[u]) {
        if (mark[v]) continue;
        cnt++;
        res.emplace_back(label[v]);
        DFS(v);
    }
    for (int v: adj[u]) {
        if (!mark[v]) continue;
        cnt++;
        res.emplace_back(label[v]);
        DFS(v);
    }
    if (n) res.emplace_back('-');
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    freopen("type.inp","r",stdin);
    freopen("type.out","w",stdout);
    cin >> n;
    string s, longest;
    for (int i = 1; i <= n; i++) {
        cin >> s;
        addString(s);
        if (longest.size() < s.size()) longest = s;
    }
    markLongest(longest);
    DFS(0);
    cout << res.size() << '\n';
    for (char c: res) cout << c << '\n';
    return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:61:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |     freopen("type.inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
printer.cpp:62:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |     freopen("type.out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12028 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12068 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 12108 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12080 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 12028 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12108 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -