Submission #107464

# Submission time Handle Problem Language Result Execution time Memory
107464 2019-04-24T16:00:31 Z tictaccat Type Printer (IOI08_printer) C++14
60 / 100
16 ms 7936 KB
#include <bits/stdc++.h>

using namespace std;

const int MAX = 25000 + 10;

int N;
vector<string> words;
string longest;

vector<vector<int>> trie(MAX,vector<int>(26));
vector<int> hasString(MAX);
int c = 0; //current max node in tree

ostringstream oss;
int ops;

void insert (const string &s) {
    int u = 0; 
    for (int i = 0; i < s.size(); i++) {
        if (trie[u][s[i]-'a']) u = trie[u][s[i]-'a'];
        else u = trie[u][s[i]-'a'] = ++c;
    }
    hasString[u] = true;
}

void dfs(int u, int adv) {
    if (hasString[u]) {
        ops++;
        oss << "P\n";
    }
    if (adv == longest.size()) {
        cout << ops << "\n" << oss.str();
        exit(0);
    }
    for (int c = 0; c < 26; c++) {
        if (c == longest[adv]-'a') continue;
        if (trie[u][c]) {
            ops++;
            oss << (char)('a'+c) << "\n";
            dfs(trie[u][c],adv);
        }
    }
    if (trie[u][longest[adv]-'a']) {
        ops++;
        oss << longest[adv] << "\n";
        dfs(trie[u][longest[adv]-'a'],adv+1);
    }
    ops++;
    oss << "-\n";
}

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;

    for (int i = 0; i < N; i++) {
        string w; cin >> w;
        words.push_back(w);
        insert(w);
    }

    longest = *max_element(words.begin(),words.end(),[](string a, string b) {return a.size() < b.size();});

    dfs(0,0);

    return 0;
}

Compilation message

printer.cpp: In function 'void insert(const string&)':
printer.cpp:20:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < s.size(); i++) {
                     ~~^~~~~~~~~~
printer.cpp: In function 'void dfs(int, int)':
printer.cpp:32:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (adv == longest.size()) {
         ~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3712 KB Output is correct
2 Correct 7 ms 3708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3840 KB Output is correct
2 Correct 7 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3712 KB Output is correct
2 Correct 8 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3712 KB Output is correct
2 Correct 6 ms 3836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3840 KB Output is correct
2 Correct 8 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3840 KB Output is correct
2 Correct 9 ms 3940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 4224 KB Output is correct
2 Runtime error 16 ms 7808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 7808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 7808 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 7936 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -