Submission #63235

# Submission time Handle Problem Language Result Execution time Memory
63235 2018-08-01T06:44:44 Z Tenuun Type Printer (IOI08_printer) C++17
20 / 100
85 ms 39580 KB
#include<bits/stdc++.h>
#define pb push_back
using namespace std;

string m;

struct node{
	char c;
	int val=0, mx=0;
	node *l[26];
	node(){
		for(int i=0; i<26; i++) {
			l[i]=NULL;
		}
	}
};

vector<char>res;

node *root=new node;

void insert(string s){
	node *now=root;
	int v;
	for(int i=0; i<s.length(); i++){
		v=s[i]-'a';
		if(now->l[v]==NULL){
			now->l[v]=new node;
			now->l[v]->c=s[i];
			now->l[v]->val++;
		}
		else{
			now->l[v]->val++;
		}
		now->mx++;
		now=now->l[v];
	}
}

void swp(){
	node *now=root;
	int ind=0;
	while(ind<m.length()){
		for(int i=0; i<26; i++){
			if(i==m[ind]-'a'){
				swap(now->l[25], now->l[i]);
				now=now->l[25];
				break;
			}
		}
		ind++;
	}
}

void print(node *now){
	int cnt=0;
	for(int i=0; i<26; i++){
		if(now->l[i]==NULL) continue;
		cnt++;
		res.pb(now->l[i]->c);
		//cout << now->l[i]->mx << " " << now->l[i]->val << endl;
		for(int j=now->l[i]->mx+1; j<now->l[i]->val; j++) res.pb('P');
		print(now->l[i]);
		res.pb('-');
	}
	if(cnt==0){
		res.pb('P');
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, t=0;
	cin >> n;
	string s;
	for(int i=0; i<n; i++){
		cin >> s;
		if(s.length()>t){
			m=s;
			t=s.length();
		}
		insert(s);
	}
	swp();
	print(root);
	while(res[res.size()-1]=='-'){
		res.pop_back();
	}
	cout << res.size() << endl;
	for(int i=0; i<res.size(); i++) if(res[i]!='#')cout << res[i] << '\n';
	return 0;
}

Compilation message

printer.cpp: In function 'void insert(std::__cxx11::string)':
printer.cpp:25:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<s.length(); i++){
               ~^~~~~~~~~~~
printer.cpp: In function 'void swp()':
printer.cpp:43:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(ind<m.length()){
        ~~~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:79:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(s.length()>t){
      ~~~~~~~~~~^~
printer.cpp:91:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<res.size(); i++) if(res[i]!='#')cout << res[i] << '\n';
               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 428 KB Output is correct
2 Correct 3 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 692 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 692 KB Output is correct
2 Incorrect 2 ms 692 KB didn't print every word
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 780 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2184 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 6676 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 16196 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 85 ms 39580 KB didn't print every word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 76 ms 39580 KB didn't print every word
2 Halted 0 ms 0 KB -