結果

問題 No.1156 Nada Picnic 2
ユーザー lloyzlloyz
提出日時 2022-07-08 15:24:31
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 1,668 ms
コンパイル使用メモリ 86,744 KB
実行使用メモリ 77,352 KB
最終ジャッジ日時 2023-08-27 14:03:07
合計ジャッジ時間 4,079 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 598 ms
77,216 KB
testcase_02 AC 1,999 ms
77,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

if len(sys.argv) == 2:
    sys.stdin = open(sys.argv[1])

from itertools import permutations

n = int(input())

if n == 1:
    a = 'abc'
    b = 'def'
    c = 'bhvb'
elif n == 2:
    a = 'aabc'
    b = 'defg'
    c = 'hibcj'
elif n == 3:
    a = 'spring'
    b = 'eight'
    c = 'picnic'

S = set()
for s in [a, b, c]:
    for ss in s:
        S.add(ss)
num = len(S)
L = list(S)
s_to_i = dict()
for i in range(num):
    s_to_i[L[i]] = i

for P in permutations(range(num)):
    if P[s_to_i[a[0]]] == 0 or P[s_to_i[b[0]]] == 0 or P[s_to_i[c[0]]] == 0:
        continue
    ANS = [0, 0, 0]
    for i in range(3):
        s = [a, b, c][i]
        for d in range(len(s)):
            ANS[i] += P[s_to_i[s[d]]] * pow(10, len(s) - d - 1)
    if ANS[0] + ANS[1] == ANS[2]:
        print(ANS[2])
        exit()
0