Submission #951838

# Submission time Handle Problem Language Result Execution time Memory
951838 2024-03-22T19:45:07 Z vjudge1 Type Printer (IOI08_printer) C++17
0 / 100
42 ms 38736 KB
#include <iostream>
#include <assert.h>
#include <algorithm>
#include <vector>

#define  DBG(x         ) cerr<<#x<<" = "<<(x)<<endl
#define DBG2(x, y      ) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<endl
#define DBG3(x, y, z   ) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<endl
#define DBG4(x, y, z, w) cerr<<#x<<" = "<<(x)<<", "<<#y<<" = "<<(y)<<", "<<#z<<" = "<<(z)<<", "<<#w<<" = "<<(w)<<endl
#define RAYA cerr<<" =============== "<<endl

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fort(i, n) for(int i = 0; i <= int(n); i++)
#define fori(i, a, n) for(int i = a; i < int(n); i++)
#define forit(i, a, n) for(int i = a; i <= int(n); i++)

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

using namespace std;

template<typename T>
ostream & operator<<(ostream &os, const vector<T> &v){
    os<<"[";
    forn(i, (int) v.size()){
        if(i) os<<", ";
        os<<v[i];
    }
    os<<"]";
    return os;
}

template<typename S, typename T>
ostream & operator<<(ostream &os, const pair<S, T> &p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int ALP = 26;

typedef struct Node *pnode;

struct Node{
	bool v = 0;
	pair<int, int> longest = {0, -1};
	pnode m[ALP];
	Node(){
		forn(i, ALP) m[i] = NULL;
	}
};

struct Trie{
	pnode root;
	Trie(){
		root = new Node();
	}
	void insert(const string &s){
		int n = s.size();
		pnode curr = root;
		for(int i = 0; i < n; i++){
			int idx = s[i] - 'a';
			curr->longest = max(curr->longest, {n-i, idx});
			if(!curr->m[idx]) curr->m[idx] = new Node();
			curr = curr->m[idx];
		}
		curr->v = 1;
	}
	void dfs(pnode curr, bool l){
		if(curr->v) cout<<"P\n";
		forn(i, ALP){
			if(!curr->m[i]) continue;
			if(curr->longest.second==i && l) continue;
			cout<<char(i+'a')<<"\n";
			dfs(curr->m[i], 0);
			cout<<"-\n";
		}
		if(curr->longest.first && l){
			cout<<char(curr->longest.second+'a')<<"\n";
			dfs(curr->m[curr->longest.second], 1);
		}
	}
	void dfs(){
		dfs(root, 1);
	}
};

void solve(){
	
	int n;
	cin>>n;
	
	Trie printer;
	while(n--){
		string s;
		cin>>s;
		printer.insert(s);
	}
	
	printer.dfs();

}

int main(){

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

    #ifdef LOCAL
        freopen("input.in", "r", stdin);
    #else
        //~ freopen("input.in", "r", stdin);
        //~ freopen("output.out", "w", stdout);
    #endif

    //~ int tcs;
    //~ cin>>tcs;
    //~ while(tcs--){
        solve();
    //~ }

    return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1884 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 6236 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 15452 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 38736 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 38 ms 30380 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -