QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#876360#7705. Make Your Own Morse Code PalindromeWeaRD276#AC ✓1ms3840kbC++203.1kb2025-01-30 20:11:192025-01-30 20:11:21

Judging History

This is the latest submission verdict.

  • [2025-01-30 20:11:21]
  • Judged
  • Verdict: AC
  • Time: 1ms
  • Memory: 3840kb
  • [2025-01-30 20:11:19]
  • Submitted

answer

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

#include  <ext/pb_ds/assoc_container.hpp>
#include  <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define x first
#define y second
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef double db;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<db, db> pdd;
typedef pair<ll, ll> pll;


int solve()
{
	//string suka = "PIDOR";
	//suka = suka.substr(5);
	//cout << suka << '\n';
	//return 0;
	
	string str;
	getline(cin, str);
	string s = "";
	for (char ch: str)
	{
		if (isalpha(ch))
			s += toupper(ch);
		else if (isdigit(ch))
			s += ch;
	}
	
	map<char, string> m;
	m['A'] = ".-";
	m['B'] = "-...";
	m['C'] = "-.-.";
	m['D'] = "-..";
	m['E'] = ".";
    m['F'] = "..-.";
    m['G'] = "--.";
    m['H'] = "....";
    m['I'] = "..";
    m['J'] = ".---";
    m['K'] = "-.-";
    m['L'] = ".-..";
    m['M'] = "--";
    m['N'] = "-.";
    m['O'] = "---";
    m['P'] = ".--.";
    m['Q'] = "--.-";
    m['R'] = ".-.";
    m['S'] = "...";
    m['T'] = "-";
    m['U'] = "..-";
    m['V'] = "...-";
    m['W'] = ".--";
    m['X'] = "-..-";
    m['Y'] = "-.--";
    m['Z'] = "--..";
    m['0'] = "-----";
    m['1'] = ".----";
    m['2'] = "..---";
    m['3'] = "...--";
    m['4'] = "....-";
    m['5'] = ".....";
    m['6'] = "-....";
    m['7'] = "--...";
    m['8'] = "---..";
    m['9'] = "----.";
    string mor = "";
    for (char ch: s)
		mor += m[ch];
	
	vector<string> vals;
	vector<char> keys;
	for (auto [key, val]: m)
	{
		vals.pb(val);
		keys.pb(key);
	}
	
	//cerr << "mor = " << mor << '\n';
	string rev = mor;
	reverse(all(rev));
	
	if (rev == mor)
	{
		cout << "0\n";
		return 0;
	}
	
	int add = 0;
	FOR (i, 0, sz(mor))
	{
		string s1 = mor.substr(i);
		string s2 = rev.substr(0, sz(mor) - i);
		//cerr << "s1 = " << s1 << " s2 = " << s2 << '\n';
		if (s1 == s2)
		{
			add = i;
			break;
		}
	}
	string need = mor.substr(0, add);
	reverse(all(need));
	string sss = "";
	while (need != "")
	{
		RFOR (i, 6, 1)
		{
			if (sz(need) >= i)
			{
				string sub = need.substr(0, i);
				auto it = find(all(vals), sub);
				if (it != vals.end())
				{
					int j = it - vals.begin();
					sss += keys[j];
					need = need.substr(i);
					break;
				}
			}
		}
	}
	cout << sz(sss) << ' ' << sss << '\n';
	
	return 0;
}

int32_t main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int TET = 1;
	//cin >> TET;
	for (int i = 1; i <= TET; i++)
	{
		if (solve())
		{
			break;
		}
		#ifdef ONPC
			cerr << "_____________________________\n";
		#endif
	}
	#ifdef ONPC
		cerr << "\nfinished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
	#endif
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

FOOT

output:

1 L

result:

ok correct

Test #2:

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

input:

FOOTS

output:

3 0QI

result:

ok correct

Test #3:

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

input:

FOOTS

output:

3 0QI

result:

ok correct

Test #4:

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

input:

FOOTSTOOL

output:

0

result:

ok correct

Test #5:

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

input:

OOTNX

output:

3 1OT

result:

ok correct

Test #6:

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

input:

3 FRENCH HENS

output:

6 5RCLXB

result:

ok correct

Test #7:

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

input:

TWAS THE NIGHT BEFORE XMAS

output:

13 YXFOL46PF4VPT

result:

ok correct

Test #8:

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

input:

1A2B3C4D5E6F7G8H9I10J

output:

18 0695OPUC5646R848YG

result:

ok correct

Test #9:

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

input:

A PARTRIDGE IN A PEAR TREE

output:

8 QF3FFCXC

result:

ok correct

Test #10:

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

input:

TEN LORDS ALEAPING

output:

9 BQ4L4R8XA

result:

ok correct

Test #11:

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

input:

XABCDQRST1234567890123456789

output:

7 6CZCBQU

result:

ok correct

Test #12:

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

input:

ASDFGHJKLQWERTYUIOPMNBVCXZ987

output:

23 ZO12FY5ROP8XYLQPRY73LFF

result:

ok correct

Test #13:

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

input:

THE QUICK BROWN FOX JUMPS OVER

output:

17 24YXQ2C2JLUCCLY5T

result:

ok correct

Test #14:

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

input:

1234567891 IS A PRIME NUMBER 0

output:

18 L37YVUC59123456789

result:

ok correct

Test #15:

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

input:

INTRANSIGENCE

output:

0

result:

ok correct

Test #16:

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

input:

ANTICKING ANTICKING WRECKING A

output:

5 CRCXP

result:

ok correct

Test #17:

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

input:

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

output:

1 E

result:

ok correct

Test #18:

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

input:

ISO9001 "IEEEEEEEEEEEEEEEEEEEE

output:

6 90018S

result:

ok correct