Submission #303768

# Submission time Handle Problem Language Result Execution time Memory
303768 2020-09-20T15:48:37 Z FlashGamezzz Type Printer (IOI08_printer) C++17
80 / 100
1000 ms 64140 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

vector<int> lets[500000];
bool endb[500000] = {};
int length[500000] = {}, sz = 0;
vector<char> ans;

void add(int c, int i, string s){
	if (i == s.length()){
		endb[c] = true; return;
	}
	int l = int(s[i])-97;
	if (lets[c][l] == 0){
		vector<int> t; t.resize(26, 0); lets[sz] = t; 
		lets[c][l] = sz; sz++;
	}
	add(lets[c][l], i+1, s);
	length[c] = max(length[lets[c][l]]+1, length[c]);
}

void solve(long c){
	if (endb[c]){
		ans.push_back('P');
	}
	bool lu = false; int dl = -1;
	for (int i = 0; i < 26; i++){
		if (lets[c][i] != 0){
			if (!lu && length[lets[c][i]] == length[c]-1){
				lu = true; dl = i;
			} else {
				ans.push_back(char(i+97));
				solve(lets[c][i]);
				ans.push_back('-');
			}
		}
	}
	if (dl > -1){
		ans.push_back(char(dl+97));
		solve(lets[c][dl]);
		ans.push_back('-');
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	vector<int> t; t.resize(26, 0); lets[sz] = t; sz++;
	for (int i = 0; i < n; i++){
		string s; cin >> s;
		add(0, 0, s);
	}
	solve(0);
	int count = ans.size();
	while (ans[count-1] == '-'){
		count--;
	}
	cout << count << endl;
	for (int i = 0; i < count; i++){
		cout << ans[i] << endl;
	}
}

Compilation message

printer.cpp: In function 'void add(int, int, std::string)':
printer.cpp:19:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   19 |  if (i == s.length()){
      |      ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 9 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 12032 KB Output is correct
2 Correct 10 ms 12104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12032 KB Output is correct
2 Correct 8 ms 12032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 12160 KB Output is correct
2 Correct 26 ms 12544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 12928 KB Output is correct
2 Correct 52 ms 13184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 15104 KB Output is correct
2 Correct 302 ms 18720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 321 ms 19828 KB Output is correct
2 Correct 107 ms 13696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 810 ms 31560 KB Output is correct
2 Execution timed out 1089 ms 56008 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 651 ms 27240 KB Output is correct
2 Execution timed out 1087 ms 64140 KB Time limit exceeded
3 Halted 0 ms 0 KB -