QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#321694#7705. Make Your Own Morse Code Palindromeishmeal#Compile Error//C++232.3kb2024-02-05 07:36:592024-02-05 07:36:59

Judging History

你现在查看的是最新测评结果

  • [2024-02-05 07:36:59]
  • 评测
  • [2024-02-05 07:36:59]
  • 提交

answer

#include "bits/stdc++.h"
using namespace std;

map<char,string> m{
	{'A', "01"},
	{'B', "1000"},
	{'C', "1010"},
	{'D', "100"},
	{'E', "0"},
	{'F', "0010"},
	{'G', "110"},
	{'H', "0000"},
	{'I', "00"},
	{'J', "0111"},
	{'K', "101"},
	{'L', "0100"},
	{'M', "11"},
	{'N', "10"},
	{'O', "111"},
	{'P', "0110"},
	{'Q', "1101"},
	{'R', "010"},
	{'S', "000"},
	{'T', "1"},
	{'U', "001"},
	{'V', "0001"},
	{'W', "011"},
	{'X', "1001"},
	{'Y', "1011"},
	{'Z', "1100"},
	{'0', "11111"},
	{'1', "01111"},
	{'2', "00111"},
	{'3', "00011"},
	{'4', "00001"},
	{'5', "00000"},
	{'6', "10000"},
	{'7', "11000"},
	{'8', "11100"},
	{'9', "11110"}
};
map<string,char> rm;

int best = INT_MAX;
string ans = "";
void build(string s, char st = ' ') {
	reverse(s.begin(),s.end());
	int n = s.size();
	vector<pair<int,string>> dp(n+1, {INT_MAX,""});
	dp[0] = {st != ' ', st};

	for (int i = 0; i < n; i++) {
		for (int j = 1; j <= 5; j++) {
			if (i+j > n) break;
			string t = s.substr(i,j);
			if (rm.count(t)) {
				dp[i+j] = min(dp[i+j], {dp[i].first+1, dp[i].second+rm[t]});
			}
		}
	}
	if (dp[n].first < best) {
		best = dp[n].first;
		ans = dp[n].second;
	}
}

string s;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	for (auto [c, ss] : m) rm[ss] = c;
	
	{
		string t; cin >> t;
		for (char c : t) assert(m.count(c)), s += m[c];
	}
	int n = s.size();

	for (int i = (n-1)/2; i < n; i++) {
		{
		int j = i+1;
		int i = j-1;
		bool good = true;
		while (j < n) {
			if (s[i] != s[j]) good = false;
			j++,i--;
		}
		if (good) build(s.substr(0, i+1));
		}
	}
	for (int i = n/2; i < n; i++) {
		{
		int j = i;
		int i = j;
		bool good = true;
		while (j < n) {
			if (s[i] != s[j]) good = false;
			j++,i--;
		}
		if (good) build(s.substr(0, i+1));
		}
	}

	for (auto [c, ss] : m) {
		string t = s + ss;
		for (int i = s.size(); i < t.size(); i++) {
			{
			int j = i+1;
			int i = j-1;
			bool good = true;
			while (j < n) {
				if (s[i] != s[j]) good = false;
				j++,i--;
			}
			if (good) build(s.substr(0, i+1), c);
			}
		}
		for (int i = s.size(); i < t.size(); i++) {
			{
			int j = i;
			int i = j;
			bool good = true;
			while (j < n) {
				if (s[i] != s[j]) good = false;
				j++,i--;
			}
			if (good) build(s.substr(0, i+1), c);
			}
		}
	}

	if (!best) cout << "0\n";
	else cout << best << ' ' << ans << '\n';
}

詳細信息

answer.code: In function ‘void build(std::string, char)’:
answer.code:50:31: error: no match for ‘operator=’ (operand types are ‘__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, std::__cxx11::basic_string<char> > >, std::pair<int, std::__cxx11::basic_string<char> > >::value_type’ {aka ‘std::pair<int, std::__cxx11::basic_string<char> >’} and ‘<brace-enclosed initializer list>’)
   50 |         dp[0] = {st != ' ', st};
      |                               ^
In file included from /usr/include/c++/13/bits/stl_algobase.h:64,
                 from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_pair.h:439:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) requires  _S_assignable<const _U1&, const _U2&>() [with _U2 = _U1; _T1 = int; _T2 = std::__cxx11::basic_string<char>]’
  439 |         operator=(const pair<_U1, _U2>& __p)
      |         ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:439:9: note:   template argument deduction/substitution failed:
answer.code:50:31: note:   couldn’t deduce template parameter ‘_U1’
   50 |         dp[0] = {st != ' ', st};
      |                               ^
/usr/include/c++/13/bits/stl_pair.h:451:9: note: candidate: ‘template<class _U1, class _U2> constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) requires  _S_assignable<_U1, _U2>() [with _U2 = _U1; _T1 = int; _T2 = std::__cxx11::basic_string<char>]’
  451 |         operator=(pair<_U1, _U2>&& __p)
      |         ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:451:9: note:   template argument deduction/substitution failed:
answer.code:50:31: note:   couldn’t deduce template parameter ‘_U1’
   50 |         dp[0] = {st != ' ', st};
      |                               ^
/usr/include/c++/13/bits/stl_pair.h:486:9: note: candidate: ‘template<class _U1, class _U2> constexpr const std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_U1, _U2>&) const requires (is_assignable_v<const first_type&, const _U1&>) && (is_assignable_v<const second_type&, const _U2&>) [with _U2 = _U1; _T1 = int; _T2 = std::__cxx11::basic_string<char>]’
  486 |         operator=(const pair<_U1, _U2>& __p) const
      |         ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:486:9: note:   template argument deduction/substitution failed:
answer.code:50:31: note:   couldn’t deduce template parameter ‘_U1’
   50 |         dp[0] = {st != ' ', st};
      |                               ^
/usr/include/c++/13/bits/stl_pair.h:498:9: note: candidate: ‘template<class _U1, class _U2> constexpr const std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_U1, _U2>&&) const requires (is_assignable_v<const first_type&, _U1>) && (is_assignable_v<const second_type&, _U2>) [with _U2 = _U1; _T1 = int; _T2 = std::__cxx11::basic_string<char>]’
  498 |         operator=(pair<_U1, _U2>&& __p) const
      |         ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:498:9: note:   template argument deduction/substitution failed:
answer.code:50:31: note:   couldn’t deduce template parameter ‘_U1’
   50 |         dp[0] = {st != ' ', st};
      |                               ^
/usr/include/c++/13/bits/stl_pair.h:416:7: note: candidate: ‘constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_T1, _T2>&) requires  _S_assignable<const _T1&, const _T2&>() [with _T1 = int; _T2 = std::__cxx11::basic_string<char>]’
  416 |       operator=(const pair& __p)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:416:29: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘const std::pair<int, std::__cxx11::basic_string<char> >&’
  416 |       operator=(const pair& __p)
      |                 ~~~~~~~~~~~~^~~
/usr/include/c++/13/bits/stl_pair.h:427:7: note: candidate: ‘constexpr std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(std::pair<_T1, _T2>&&) requires  _S_assignable<_T1, _T2>() [with _T1 = int; _T2 = std::__cxx11::basic_string<char>]’
  427 |       operator=(pair&& __p)
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:427:24: note:   no known conversion for argument 1 from ‘<brace-enclosed initializer list>’ to ‘std::pair<int, std::__cxx11::basic_string<char> >&&’
  427 |       operator=(pair&& __p)
      |                 ~~~~~~~^~~
/usr/include/c++/13/bits/stl_pair.h:463:7: note: candidate: ‘constexpr const std::pair<_T1, _T2>& std::pair<_T1, _T2>::operator=(const std::pair<_T1, _T2>&) const requires (is_copy_assignable_v<const first_type>) && (is_copy_assignable_v<const second_type>) [with _T1 = int; _T2 = std::__cxx11::basic_string<char>]’
  463 |       operator=(const pair& __p) const
      |       ^~~~~~~~
/usr/include/c++/13/bits/stl_pair.h:463:7: note: constraints not satisfied
/usr/include/c++/13/bits/stl_pair.h: In instantiation of ‘conste...