Submission #1108349

# Submission time Handle Problem Language Result Execution time Memory
1108349 2024-11-03T21:56:44 Z vjudge1 Type Printer (IOI08_printer) C++17
20 / 100
63 ms 36100 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define ll long long
#define endl "\n"
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define tam(s) (int)s.size()
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
 
typedef vector<int> vi;
typedef pair<int, char> pic;
typedef tuple<int, int, int> tii;
const int lim=500001;
int t[lim];

int32_t main(){
    fastio;
 
    int n, k=0, l;
    string s, ans="";
    cin >> n;
    map<char, int> m[lim];
    
    rep(i, 0, n){
        cin >> s;
        int j=0, p=0;
        for(char c: s){
            auto it = m[j].find(c);
            if(it == m[j].end()) m[j][c] = ++k, j=k;
            else j=m[j][c];
            t[j] = max(t[j], tam(s)-p);
            p++;
        }
    }

    auto dfs=[&] (auto self, int i) -> void {
        if(m[i].empty()){
            ans += 'P';
            l = tam(ans);
            return;
        }
        vector<pic> v;
        for(auto [a, b] : m[i]) v.eb(t[b], a);
        sort(all(v));
        for(auto [a, b] : v){
            ans += b;
            self(self, m[i][b]);
            ans += '-';
        }
    };
    dfs(dfs, 0);
    cout << l << endl;
    rep(i, 0, l) cout << ans[i] << endl;

    return 0;    
}
# Verdict Execution time Memory Grader output
1 Correct 21 ms 23888 KB Output is correct
2 Correct 21 ms 23888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23888 KB Output is correct
2 Correct 20 ms 23768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 23888 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23888 KB Output is correct
2 Incorrect 26 ms 24148 KB didn't print every word
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 23888 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 24400 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 25680 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 28892 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 36100 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 57 ms 33784 KB didn't print every word
2 Halted 0 ms 0 KB -