Submission #803271

# Submission time Handle Problem Language Result Execution time Memory
803271 2023-08-03T03:20:13 Z UmairAhmadMirza Type Printer (IOI08_printer) C++17
90 / 100
1000 ms 113332 KB
#include <bits/stdc++.h>
using namespace std;
int const N=1e5+5;

struct node
{
	char ch;
	map<char,node*> mp;
	set<pair<int,node*>> adj;
	int dep=1;
	int cnt=0;
};
node* root;
void add(){
	string s;
	cin>>s;
	int i=0;
	node* cur=root;
	while(i<s.length()){
		if(cur->mp[s[i]]==NULL){
			cur->mp[s[i]]=new node();
			cur->mp[s[i]]->ch=s[i];
		}
		cur=cur->mp[s[i]];
		i++;
	}
	cur->cnt++;
}
int dep_set(node* rt){
	for(auto i:rt->mp){
		rt->dep=max(rt->dep,dep_set(i.second)+1);
		rt->adj.insert({i.second->dep,i.second});
	}
	return rt->dep;
}
vector<char> ans;
void dfs1(node* rt){
	for (int i = 0; i < rt->cnt; ++i)
		ans.push_back('P');
	for(auto i:rt->adj){
		ans.push_back(i.second->ch);
		dfs1(i.second);
		ans.push_back('-');
	}
}
int main(){
	int t;
	cin>>t;
	root=new node();
	for (int i = 0; i < t; ++i)
		add();
	dep_set(root);
	dfs1(root);
	int sz=ans.size();
	while(sz>0&&ans[sz-1]=='-'){
		ans.pop_back();
		sz--;
	}
	cout<<sz<<endl;
	for(auto i:ans)
		cout<<i<<endl;
	return 0;
}

Compilation message

printer.cpp: In function 'void add()':
printer.cpp:19:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  while(i<s.length()){
      |        ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 9 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2028 KB Output is correct
2 Correct 23 ms 2480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 6736 KB Output is correct
2 Correct 124 ms 14244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 16692 KB Output is correct
2 Correct 44 ms 3760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 385 ms 41656 KB Output is correct
2 Correct 845 ms 95272 KB Output is correct
3 Correct 457 ms 49096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 331 ms 32476 KB Output is correct
2 Execution timed out 1022 ms 113332 KB Time limit exceeded
3 Halted 0 ms 0 KB -