Submission #115184

# Submission time Handle Problem Language Result Execution time Memory
115184 2019-06-05T23:07:58 Z ly20 Type Printer (IOI08_printer) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
#define debug(args...) //fprintf(stderr,args)
const int MAXN=25010,MAXL=30;
int trie[MAXN*MAXL][MAXL],vl[MAXN*MAXL],cont[MAXN*MAXL],pos[MAXN*MAXL],end[MAXN*MAXL],pt[MAXN*MAXL];
int at;
vector<char> rs;
string s1;
string sr;
int tmn;
void tr(int v)
{
	if(v!=0)
	{
		rs.push_back(vl[v]+'a');
	}
	for(int i=0;i<MAXL;i++)
	{
		if(trie[v][i]!=0 && pt[trie[v][i]]!=1)
		{
			tr(trie[v][i]);
			if(end[trie[v][i]])rs.push_back('P');
			rs.push_back('-');
		}
	}
	int id;
	if(tmn>pos[v])
	{
		id=sr[pos[v]]-'a';
		if(pt[trie[v][id]]==1)
		{
			tr(trie[v][id]);
			if(end[trie[v][id]])rs.push_back('P');
		}
	}
}
void add(string s)
{
	int cur=0;
	int tm=s.size();
	for(int i=0;i<tm;i++)
	{
		cont[cur]++;
		int id=s[i]-'a';
		if(trie[cur][id]==0)
		{
			trie[cur][id]=++at;
			vl[at]=id;
			pos[at]=i+1;
		}
		cur=trie[cur][id];
	}
	end[cur]=1;
}
void pt1(string s)
{
	int cur=0;
	int tm=s.size();
	for(int i=0;i<tm;i++)
	{
		int id=s[i]-'a';
		cur=trie[cur][id];
		pt[cur]=1;
	}
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		cin>>s1;
		if(s1.size()>sr.size())sr=s1;
		add(s1);
	}
	pt1(sr);
	tmn=sr.size();
	tr(0);
	printf("%d\n",rs.size());
	for(int i=0;i<rs.size();i++)printf("%c\n",rs[i]);
	return 0;
}

Compilation message

printer.cpp: In function 'void tr(int)':
printer.cpp:22:7: error: reference to 'end' is ambiguous
    if(end[trie[v][i]])rs.push_back('P');
       ^~~
printer.cpp:5:72: note: candidates are: int end [750300]
 int trie[MAXN*MAXL][MAXL],vl[MAXN*MAXL],cont[MAXN*MAXL],pos[MAXN*MAXL],end[MAXN*MAXL],pt[MAXN*MAXL];
                                                                        ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
                 from printer.cpp:1:
/usr/include/c++/7/valarray:1231:5: note:                 template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)
     end(const valarray<_Tp>& __va)
     ^~~
/usr/include/c++/7/valarray:1221:5: note:                 template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)
     end(valarray<_Tp>& __va)
     ^~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from printer.cpp:1:
/usr/include/c++/7/bits/range_access.h:97:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^~~
/usr/include/c++/7/bits/range_access.h:78:5: note:                 template<class _Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^~~
/usr/include/c++/7/bits/range_access.h:68:5: note:                 template<class _Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^~~
In file included from /usr/include/c++/7/bits/range_access.h:36:0,
                 from /usr/include/c++/7/string:51,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from printer.cpp:1:
/usr/include/c++/7/initializer_list:99:5: note:                 template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^~~
printer.cpp:33:7: error: reference to 'end' is ambiguous
    if(end[trie[v][id]])rs.push_back('P');
       ^~~
printer.cpp:5:72: note: candidates are: int end [750300]
 int trie[MAXN*MAXL][MAXL],vl[MAXN*MAXL],cont[MAXN*MAXL],pos[MAXN*MAXL],end[MAXN*MAXL],pt[MAXN*MAXL];
                                                                        ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
                 from printer.cpp:1:
/usr/include/c++/7/valarray:1231:5: note:                 template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)
     end(const valarray<_Tp>& __va)
     ^~~
/usr/include/c++/7/valarray:1221:5: note:                 template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)
     end(valarray<_Tp>& __va)
     ^~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from printer.cpp:1:
/usr/include/c++/7/bits/range_access.h:97:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^~~
/usr/include/c++/7/bits/range_access.h:78:5: note:                 template<class _Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^~~
/usr/include/c++/7/bits/range_access.h:68:5: note:                 template<class _Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^~~
In file included from /usr/include/c++/7/bits/range_access.h:36:0,
                 from /usr/include/c++/7/string:51,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from printer.cpp:1:
/usr/include/c++/7/initializer_list:99:5: note:                 template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^~~
printer.cpp: In function 'void add(std::__cxx11::string)':
printer.cpp:53:2: error: reference to 'end' is ambiguous
  end[cur]=1;
  ^~~
printer.cpp:5:72: note: candidates are: int end [750300]
 int trie[MAXN*MAXL][MAXL],vl[MAXN*MAXL],cont[MAXN*MAXL],pos[MAXN*MAXL],end[MAXN*MAXL],pt[MAXN*MAXL];
                                                                        ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:95:0,
                 from printer.cpp:1:
/usr/include/c++/7/valarray:1231:5: note:                 template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)
     end(const valarray<_Tp>& __va)
     ^~~
/usr/include/c++/7/valarray:1221:5: note:                 template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)
     end(valarray<_Tp>& __va)
     ^~~
In file included from /usr/include/c++/7/string:51:0,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from printer.cpp:1:
/usr/include/c++/7/bits/range_access.h:97:5: note:                 template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])
     end(_Tp (&__arr)[_Nm])
     ^~~
/usr/include/c++/7/bits/range_access.h:78:5: note:                 template<class _Container> decltype (__cont.end()) std::end(const _Container&)
     end(const _Container& __cont) -> decltype(__cont.end())
     ^~~
/usr/include/c++/7/bits/range_access.h:68:5: note:                 template<class _Container> decltype (__cont.end()) std::end(_Container&)
     end(_Container& __cont) -> decltype(__cont.end())
     ^~~
In file included from /usr/include/c++/7/bits/range_access.h:36:0,
                 from /usr/include/c++/7/string:51,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from printer.cpp:1:
/usr/include/c++/7/initializer_list:99:5: note:                 template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
     end(initializer_list<_Tp> __ils) noexcept
     ^~~
printer.cpp: In function 'int main()':
printer.cpp:79:25: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n",rs.size());
                ~~~~~~~~~^
printer.cpp:80:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<rs.size();i++)printf("%c\n",rs[i]);
              ~^~~~~~~~~~
printer.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~