結果

問題 No.3082 Make Palindromic Multiple(Judge)
ユーザー 👑 binap
提出日時 2025-03-27 01:35:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 82,584 KB
実行使用メモリ 109,168 KB
最終ジャッジ日時 2025-03-28 01:23:37
合計ジャッジ時間 12,551 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 65 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def pow_mod(n, k, MOD):
	if k == 0:
		return 1 % MOD
	res = 1 % MOD
	while k > 0:
		if k & 1:
			res *= n
			res %= MOD
		k >>= 1
		n = (n * n) % MOD
	return res
	
# MOD >= 2
def inv_mod(n, MOD):
	return pow_mod(n, MOD - 2, MOD)

K = int(input())
S_list = []
T_list = []
for i in range(K):
	s, t = input().split()
	S_list.append(s)
	T_list.append(int(t))

MOD = 100000007
base = 114514

hash = [0, 0]

for t in range(2):
	x = 0
	
	for i in range(K):
		sz = len(S_list[i])
		p = pow_mod(base, sz, MOD)
		q = pow_mod(p, T_list[i], MOD)
		
		y = 0
		for j in range(sz):
			y *= base
			y += ord(S_list[i][j])
			y %= MOD
		
		x = x * q + (y * (q - 1) % MOD) * inv_mod(p - 1, MOD)
		x %= MOD
	
	hash[t] = x
	
	S_list.reverse()
	T_list.reverse()
	for i in range(K):
		S_list[i] = S_list[i][::-1]

if hash[0] == hash[1]:
	print("Yes")
else:
	print("No")
0