結果

問題 No.2845 Birthday Pattern in Two Different Calendars
ユーザー LyricalMaestro
提出日時 2025-05-25 14:43:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,266 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 82,040 KB
実行使用メモリ 112,708 KB
最終ジャッジ日時 2025-05-25 14:43:26
合計ジャッジ時間 4,370 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2845

from collections import deque


def solve(K, M, N):
    if M == 1:
        return ["No"]
    
    # サイクル検出
    cycles = []
    passed = [False] * K
    for s_i in range(K):
        if not passed[s_i]:
            passed[s_i] = True
            cycle = [s_i]
            v = (s_i + M - 1) % K
            while v != s_i:
                passed[v] = True
                cycle.append(v)
                v = (v + M - 1) % K
            
            cycles.append(cycle)
        
    pairs = []
    for cycle in cycles:

        for i in range(0, len(cycle), 2):
            x = cycle[i]
            if i + 1< len(cycle):
                y = cycle[i + 1]
                pairs.append((x + 1, y + 1))
    
    if len(pairs) < N:
        return ["No"]
    
    ans = [-1] * N
    for i in range(N):
        x, y = pairs[i]
        ans[i] = x
    return ["Yes", " ".join(map(str, ans))]





            







def main():
    T = int(input())

    answers = []
    for _ in range(T):
        K, M, N = map(int, input().split())
        ans = solve(K, M, N)
        answers.append(ans)

    for ans in answers:
        for a in ans:
            print(a)


    


        

    



if __name__ == "__main__":
    main()
0