結果

問題 No.1366 交換門松列・梅
コンテスト
ユーザー RK-4869
提出日時 2026-03-22 21:24:59
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 99 ms / 1,000 ms
コード長 1,196 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 355 ms
コンパイル使用メモリ 20,832 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-03-22 21:25:05
合計ジャッジ時間 2,623 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

# 門松列かどうかを判定する関数
def is_kadomatsu(a, b, c):
    if a == b or b == c or a == c:
        return False
    return (b > a and b > c) or (b < a and b < c)

# 1. 入力をリストとして受け取る
A = list(map(int, input().split())) # 1つ目の数列
B = list(map(int, input().split())) # 2つ目の数列

can_make = False

# 2. 全通りの交換を試す (3 × 3 = 9通り)
for i in range(3):     # Aの何番目を選ぶか
    for j in range(3): # Bの何番目を選ぶか
        
        # --- 交換作業 ---
        # 一時的にリストをコピーして、要素を入れ替える
        temp_A = A[:] # リストをコピー
        temp_B = B[:]
        
        # A[i] と B[j] を交換
        temp_A[i], temp_B[j] = temp_B[j], temp_A[i]
        
        # --- 判定 ---
        # 両方のリストが門松列になっているかチェック
        if is_kadomatsu(temp_A[0], temp_A[1], temp_A[2]) and \
           is_kadomatsu(temp_B[0], temp_B[1], temp_B[2]):
            can_make = True
            break # 1つでも見つかれば、内側のループを抜ける

# 3. 結果の出力
if can_make:
    print("Yes")
else:
    print("No")
0