Official
D - 隣り合う文字/Character Adjacent Editorial
by
D - 隣り合う文字/Character Adjacent Editorial
by
sounansya
問題文に書かれた通りに \(h_1,h_2,w_1,w_2\) の \(4\) 重ループを作成すれば良いです。
Python などの言語での入力の受け取り方に注意してください。
実装例
h, w, c1, c2 = map(str, input().split())
h, w = int(h), int(w)
s = [input() for i in range(h)]
for h1 in range(h):
for h2 in range(h):
for w1 in range(w):
for w2 in range(w):
if (
s[h1][w1] == c1
and s[h2][w2] == c2
and abs(h1 - h2) + abs(w1 - w2) == 1
):
print("Yes")
exit()
print("No")
posted:
last update:
