Submission #688597

# Submission time Handle Problem Language Result Execution time Memory
688597 2023-01-27T19:52:49 Z rieyuw Type Printer (IOI08_printer) C++17
20 / 100
108 ms 70224 KB
#include <bits/stdc++.h>

using namespace std;

const int TOTAL = 25000*20;

vector<vector<int>> nxt(TOTAL, vector<int>(26));
vector<int> cnt(TOTAL);

string ans = "";
void count(int node)
{
    cnt[node] = 1;
    for (int i = 0; i < 26; ++i)
    {
        if (nxt[node][i] != 0)
        {
            count(nxt[node][i]);
            cnt[node] += cnt[nxt[node][i]];
        }
    }
}

void dfs(int node)
{
    vector<pair<int,int>> que; que.reserve(26);
    for (int i = 0; i < 26; ++i)
        if (nxt[node][i] != 0)
            que.push_back({cnt[nxt[node][i]], i});
    sort(que.begin(), que.end());
    
    bool term = (que.size() == 0);
    for (auto& p : que)
    {
        ans +=(char)('a'+p.second);
        dfs(nxt[node][p.second]);
        ans += '-';
    }
    if (term)
        ans += 'P';
}

int main() 
{
    ios::sync_with_stdio(0), cin.tie(0);
    int n; cin >> n;
    int MAXID = 0;
    ans.reserve(3*n);
    while(n--)
    {
        string s; cin >> s;
        int node = 0;
        for (char c : s)
        {
            if (nxt[node][c-'a'] == 0) 
                nxt[node][c-'a'] = ++MAXID;
            node = nxt[node][c-'a'];
        }
    }
    count(0);
    dfs(0);
    while(ans.back() == '-')
        ans.pop_back();
    cout << ans.size() << "\n";
    for (char c : ans)
        cout << c << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 42 ms 68816 KB Output is correct
2 Correct 43 ms 68692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 68856 KB Output is correct
2 Correct 44 ms 68792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 68764 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 55 ms 68728 KB Output is correct
2 Incorrect 51 ms 68776 KB didn't print every word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 59 ms 68804 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 68872 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 68956 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 69420 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 70224 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 69836 KB didn't print every word
2 Halted 0 ms 0 KB -