Submission #303741

# Submission time Handle Problem Language Result Execution time Memory
303741 2020-09-20T15:35:15 Z FlashGamezzz Type Printer (IOI08_printer) C++17
Compilation error
0 ms 0 KB
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>

using namespace std;

vector< vector<int> > lets;
vector<bool> endb;
vector<int> length;
vector<char> ans;

void add(int c, int i, string s){
	if (i == s.length()){
		endb[c] = true; length[c] = max(0, length[c]);
		return;
	}
	int l = int(s[i])-97;
	if (lets[c][l] == 0){
		vector<int> t;
		for (int j = 0; j < 26; j++) t.push_back(0);
		lets.push_back(t); endb.push_back(false); length.push_back(-100);
		lets[c][l] = lets.size()-1;
	}
	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<long> t;
	for (int j = 0; j < 26; j++) t.push_back(0);
	lets.push_back(t); endb.push_back(false); length.push_back(-100);
	for (int i = 0; i < n; i++){
		string s; cin >> s;
		add(0, 0, s);
	}
	solve(0);
	long 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()){
      |      ~~^~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:62:18: error: no matching function for call to 'std::vector<std::vector<int> >::push_back(std::vector<long int>&)'
   62 |  lets.push_back(t); endb.push_back(false); length.push_back(-100);
      |                  ^
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from printer.cpp:5:
/usr/include/c++/9/bits/stl_vector.h:1184:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::value_type = std::vector<int>]'
 1184 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1184:35: note:   no known conversion for argument 1 from 'std::vector<long int>' to 'const value_type&' {aka 'const std::vector<int>&'}
 1184 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/9/bits/stl_vector.h:1200:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::vector<int>; _Alloc = std::allocator<std::vector<int> >; std::vector<_Tp, _Alloc>::value_type = std::vector<int>]'
 1200 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/9/bits/stl_vector.h:1200:30: note:   no known conversion for argument 1 from 'std::vector<long int>' to 'std::vector<std::vector<int> >::value_type&&' {aka 'std::vector<int>&&'}
 1200 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~