結果
| 問題 | 
                            No.2845 Birthday Pattern in Two Different Calendars
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2025-05-25 14:39:51 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,270 bytes | 
| コンパイル時間 | 1,055 ms | 
| コンパイル使用メモリ | 81,604 KB | 
| 実行使用メモリ | 111,896 KB | 
| 最終ジャッジ日時 | 2025-05-25 14:39:58 | 
| 合計ジャッジ時間 | 6,172 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 9 WA * 13 | 
ソースコード
## 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 + 1
    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()