Submission #303786

# Submission time Handle Problem Language Result Execution time Memory
303786 2020-09-20T16:04:06 Z FlashGamezzz Type Printer (IOI08_printer) C++17
0 / 100
109 ms 32256 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(){
	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--;
	}
	printf("%ld \n\r", count);
	for (int i = 0; i < count; i++){
		printf("%c \n\r", ans[i]);
	}
}

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()){
      |      ~~^~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:66:12: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'int' [-Wformat=]
   66 |  printf("%ld \n\r", count);
      |          ~~^        ~~~~~
      |            |        |
      |            long int int
      |          %d
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12160 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12032 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12160 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 12928 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 15232 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 20164 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 109 ms 32256 KB Expected EOLN
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 96 ms 28016 KB Expected EOLN
2 Halted 0 ms 0 KB -