답안 #303763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
303763 2020-09-20T15:47:36 Z FlashGamezzz Type Printer (IOI08_printer) C++17
컴파일 오류
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<int> lets[500000];
bool endb[500000] = {};
int length[500000] = {}, size = 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[size] = t; 
		lets[c][l] = size; size++;
	}
	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[size] = t; size++;
	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()){
      |      ~~^~~~~~~~~~~~~
printer.cpp:24:40: error: reference to 'size' is ambiguous
   24 |   vector<int> t; t.resize(26, 0); lets[size] = t;
      |                                        ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from printer.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
printer.cpp:15:26: note:                 'int size'
   15 | int length[500000] = {}, size = 0;
      |                          ^~~~
printer.cpp:25:16: error: reference to 'size' is ambiguous
   25 |   lets[c][l] = size; size++;
      |                ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from printer.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
printer.cpp:15:26: note:                 'int size'
   15 | int length[500000] = {}, size = 0;
      |                          ^~~~
printer.cpp:25:22: error: reference to 'size' is ambiguous
   25 |   lets[c][l] = size; size++;
      |                      ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from printer.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
printer.cpp:15:26: note:                 'int size'
   15 | int length[500000] = {}, size = 0;
      |                          ^~~~
printer.cpp: In function 'int main()':
printer.cpp:57:39: error: reference to 'size' is ambiguous
   57 |  vector<int> t; t.resize(26, 0); lets[size] = t; size++;
      |                                       ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from printer.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
printer.cpp:15:26: note:                 'int size'
   15 | int length[500000] = {}, size = 0;
      |                          ^~~~
printer.cpp:57:50: error: reference to 'size' is ambiguous
   57 |  vector<int> t; t.resize(26, 0); lets[size] = t; size++;
      |                                                  ^~~~
In file included from /usr/include/c++/9/string:54,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from printer.cpp:1:
/usr/include/c++/9/bits/range_access.h:252:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  252 |     size(const _Tp (&/*__array*/)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/9/bits/range_access.h:242:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  242 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
printer.cpp:15:26: note:                 'int size'
   15 | int length[500000] = {}, size = 0;
      |                          ^~~~