QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#363583#7705. Make Your Own Morse Code Palindromepipoika#TL 31ms9908kbPython31.5kb2024-03-24 00:32:112024-03-24 00:32:11

Judging History

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

  • [2024-03-24 00:32:11]
  • 评测
  • 测评结果:TL
  • 用时:31ms
  • 内存:9908kb
  • [2024-03-24 00:32:11]
  • 提交

answer

from collections import defaultdict, deque

word = input()


morse = defaultdict(lambda: "", {
    "A": ".-",
    "B": "-...",
    "C": "-.-.",
    "D": "-..",
    "E": ".",
    "F": "..-.",
    "G": "--.",
    "H": "....",
    "I": "..",
    "J": ".---",
    "K": "-.-",
    "L": ".-..",
    "M": "--",
    "N": "-.",
    "O": "---",
    "P": ".--.",
    "Q": "--.-",
    "R": ".-.",
    "S": "...",
    "T": "-",
    "U": "..-",
    "V": "...-",
    "W": ".--",
    "X": "-..-",
    "Y": "-.--",
    "Z": "--..",
    "0": "-----",
    "1": ".----",
    "2": "..---",
    "3": "...--",
    "4": "....-",
    "5": ".....",
    "6": "-....",
    "7": "--...",
    "8": "---..",
    "9": "----.",
})

def getMorse(s):
    return "".join([morse[c] for c in s])

p = (getMorse(word))
# print(p)

def isP(s):
    return "".join(reversed(s)) == s
def outsideM(f, s):
    m = min(map(len, [f, s]))
    # return 
    # print(f, "$", s)
    # print(f[:len(s)], "$",  (''.join(reversed(s))))
    return f[:m] == ''.join(reversed(s))[:m]

if isP(p):
    print(0)
    quit()

a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
q = deque()

q.append("")
while q:
    n = q.popleft()
    # print(n, q)
    for c in a:
        suff = c + n
        m = getMorse(suff)
        if not outsideM(p, m):
            continue
        # print("Valid outside")
        if isP(p + m):
            print(len(suff), suff)
            quit()
        q.append(suff)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 11ms
memory: 9816kb

input:

FOOT

output:

1 L

result:

ok correct

Test #2:

score: 0
Accepted
time: 3ms
memory: 9796kb

input:

FOOTS

output:

3 0GD

result:

ok correct

Test #3:

score: 0
Accepted
time: 11ms
memory: 9904kb

input:

FOOTS

output:

3 0GD

result:

ok correct

Test #4:

score: 0
Accepted
time: 11ms
memory: 9908kb

input:

FOOTSTOOL

output:

0

result:

ok correct

Test #5:

score: 0
Accepted
time: 6ms
memory: 9820kb

input:

OOTNX

output:

2 J0

result:

ok correct

Test #6:

score: 0
Accepted
time: 31ms
memory: 9900kb

input:

3 FRENCH HENS

output:

6 HFCLXB

result:

ok correct

Test #7:

score: -100
Time Limit Exceeded

input:

TWAS THE NIGHT BEFORE XMAS

output:


result: