結果

問題 No.3041 非対称じゃんけん
ユーザー qwewe
提出日時 2025-05-14 13:16:38
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 3,479 bytes
コンパイル時間 667 ms
コンパイル使用メモリ 67,972 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-05-14 13:18:17
合計ジャッジ時間 1,540 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> // Include the standard input/output library

int main() {
    // Optimize input/output operations for speed.
    // std::ios_base::sync_with_stdio(false) disables synchronization with C standard I/O library, potentially making I/O faster.
    // std::cin.tie(NULL) unties the standard input stream (cin) from the standard output stream (cout), preventing automatic flushes which can improve performance.
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    
    int N; // Declare an integer variable N to store the initial number of petals.
    std::cin >> N; // Read the integer N from standard input.
    
    // Analyze the game based on the rules and optimal play strategy.
    // The game is an impartial game, meaning the available moves depend only on the state (number of petals remaining), not on which player is moving.
    // The core difference from standard games is the winning condition, which depends on the parity of the total number of petals N.
    
    // Case 1: N is odd.
    // When the total number of petals N is odd, the k-th petal removed determines the state: "Suki" if k is odd, "Kirai" if k is even.
    // Since N is odd, the state after removing the N-th (last) petal is "Suki".
    // The rules state that if the final state is "Suki", the player who made the last move wins.
    // This corresponds exactly to the rules of normal play in combinatorial game theory.
    // The game is equivalent to a subtraction game on a single pile of size N, where players can remove 1, 2, or 3 items.
    // In normal play for this specific game, the losing positions (P-positions) are states k where k is a multiple of 4 (k % 4 == 0).
    // The winning positions (N-positions) are states k where k is not a multiple of 4 (k % 4 != 0).
    // The first player (Kannazuki) wins if the starting position N is an N-position.
    // Since N is odd, N cannot be a multiple of 4 (i.e., N % 4 is 1 or 3). Thus, N is always an N-position.
    // Therefore, if N is odd, Kannazuki wins.

    // Case 2: N is even.
    // When the total number of petals N is even, the state after removing the N-th (last) petal is "Kirai".
    // The rules state that if the final state is "Kirai", the player who made the last move loses.
    // This corresponds exactly to the rules of misere play in combinatorial game theory.
    // The game is again equivalent to a subtraction game on a single pile of size N with moves {1, 2, 3}, but under misere play rules.
    // For this specific subtraction game under misere play, the losing positions (P-positions) are states k where k is congruent to 1 modulo 4 (k % 4 == 1).
    // The winning positions (N-positions) are states k where k is not congruent to 1 modulo 4 (k % 4 != 1).
    // The first player (Kannazuki) wins if the starting position N is an N-position.
    // Since N is even, N % 4 can be 0 or 2. In either case, N is not congruent to 1 modulo 4.
    // Thus, N is always an N-position.
    // Therefore, if N is even, Kannazuki wins.

    // Overall Conclusion:
    // In both possible cases (N odd or N even), the starting position N is a winning position (N-position) for the first player.
    // Assuming optimal play from both sides, the first player, Kannazuki, will always win.
    
    std::cout << "Yes" << std::endl; // Output "Yes" followed by a newline character, indicating Kannazuki wins.
    
    return 0; // Return 0 to indicate successful program execution.
}
0