QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#321705#7705. Make Your Own Morse Code PalindromeishmealAC ✓1ms3868kbC++232.3kb2024-02-05 08:48:462024-02-05 08:48:46

Judging History

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

  • [2024-02-05 08:48:46]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3868kb
  • [2024-02-05 08:48:46]
  • 提交

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; getline(cin, t);
		for (char c : t) if (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 < t.size()) {
//				if (t[i] != t[j]) good = false;
//				j++,i--;
//			}
//			if (good) build(t.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 < t.size()) {
//				if (t[i] != t[j]) good = false;
//				j++,i--;
//			}
//			if (good) build(t.substr(0, i+1), c);
//			}
//		}
//	}

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

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3700kb

input:

FOOT

output:

1 L

result:

ok correct

Test #2:

score: 0
Accepted
time: 0ms
memory: 3864kb

input:

FOOTS

output:

3 1OL

result:

ok correct

Test #3:

score: 0
Accepted
time: 1ms
memory: 3552kb

input:

FOOTS

output:

3 1OL

result:

ok correct

Test #4:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

FOOTSTOOL

output:

0

result:

ok correct

Test #5:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

OOTNX

output:

2 J0

result:

ok correct

Test #6:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

3 FRENCH HENS

output:

6 5RCLD7

result:

ok correct

Test #7:

score: 0
Accepted
time: 0ms
memory: 3664kb

input:

TWAS THE NIGHT BEFORE XMAS

output:

13 R8DKGB3576LRQ

result:

ok correct

Test #8:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

1A2B3C4D5E6F7G8H9I10J

output:

18 0695MKBQ5L5P4J51F9

result:

ok correct

Test #9:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

A PARTRIDGE IN A PEAR TREE

output:

8 QF3FFCXC

result:

ok correct

Test #10:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

TEN LORDS ALEAPING

output:

9 BG6C5C8DK

result:

ok correct

Test #11:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

XABCDQRST1234567890123456789

output:

7 6CZCBGX

result:

ok correct

Test #12:

score: 0
Accepted
time: 1ms
memory: 3832kb

input:

ASDFGHJKLQWERTYUIOPMNBVCXZ987

output:

23 AXQ88C7VJP8DQCPYFY73LFF

result:

ok correct

Test #13:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

THE QUICK BROWN FOX JUMPS OVER

output:

17 24YXQ2C2AG6GCDXP4

result:

ok correct

Test #14:

score: 0
Accepted
time: 1ms
memory: 3616kb

input:

1234567891 IS A PRIME NUMBER 0

output:

18 C48R7XC59123456789

result:

ok correct

Test #15:

score: 0
Accepted
time: 0ms
memory: 3828kb

input:

INTRANSIGENCE

output:

0

result:

ok correct

Test #16:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

ANTICKING ANTICKING WRECKING A

output:

5 CRCXP

result:

ok correct

Test #17:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

output:

1 E

result:

ok correct

Test #18:

score: 0
Accepted
time: 1ms
memory: 3860kb

input:

ISO9001 "IEEEEEEEEEEEEEEEEEEEE

output:

6 90018S

result:

ok correct