Submission #237282

# Submission time Handle Problem Language Result Execution time Memory
237282 2020-06-05T17:24:13 Z nikatamliani Type Printer (IOI08_printer) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100, M = 25005;
int codes[N][26], end[N * 26];
bool marked[N * 26];
int n, tries, maxLength, maxString;
string ans, s[M];
void add(string &s, bool mark){
	int code = 0;
	for(int i = 0; i < (int)s.size(); ++i){
		int c = s[i] - 'a'; 
		if(!codes[code][c]){
			codes[code][c] = ++tries;
		}
		code = codes[code][c];
		marked[code] = mark;
	}
	end[code] += !mark;
}
void findMinTime(int code){
	for(int i = 0; i < end[code]; ++i)ans += 'P';
	int last = -1;
	for(int i = 0; i < 26; ++i){
		if(!codes[code][i])continue;
		if(marked[codes[code][i]]){
			last = i;
		}else{
			ans += char(i + 'a');
			findMinTime(codes[code][i]);
			ans += '-';
		}
	}
	if(~last){
		ans += char(last + 'a');
		findMinTime(codes[code][last]);
		ans += '-';
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> s[i];
		add(s[i], 0);
		if(maxLength < (int)s[i].size()){
			maxLength = (int)s[i].size();
			maxString = i;
		}
	}
	add(s[maxString], 1);
	findMinTime(0);
	int trash = (int)ans.size() - 1;
	while(ans[trash] == '-')trash--;
	ans = ans.substr(0, trash + 1);
	cout << (int)ans.size() << endl;
	for(int i = 0; i < (int)ans.size(); ++i){
		cout << ans[i] << '\n';
	}
}

Compilation message

printer.cpp: In function 'void add(std::__cxx11::string&, bool)':
printer.cpp:18:2: error: reference to 'end' is ambiguous
  end[code] += !mark;
  ^~~
printer.cpp:4:19: note: candidates are: int end [26002600]
 int codes[N][26], end[N * 26];
                   ^~~
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 findMinTime(int)':
printer.cpp:21:21: error: reference to 'end' is ambiguous
  for(int i = 0; i < end[code]; ++i)ans += 'P';
                     ^~~
printer.cpp:4:19: note: candidates are: int end [26002600]
 int codes[N][26], end[N * 26];
                   ^~~
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
     ^~~