結果
問題 |
No.582 キャンディー・ボックス3
|
ユーザー |
![]() |
提出日時 | 2025-05-14 13:09:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,240 bytes |
コンパイル時間 | 593 ms |
コンパイル使用メモリ | 68,260 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-14 13:10:10 |
合計ジャッジ時間 | 1,448 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 WA * 5 |
ソースコード
#include <iostream> // Include the standard input/output library // The main function where the program execution begins int main() { // Optimize standard input/output operations for faster execution. // std::ios_base::sync_with_stdio(false) disables synchronization with C standard streams. // std::cin.tie(NULL) unties cin from cout, meaning flushing cout won't be forced before cin operations. std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int N; // Declare an integer variable N to store the number of boxes. std::cin >> N; // Read the number of boxes from standard input. long long C_i; // Declare a long long variable C_i to store the number of candies in the current box. // Use long long because the number of candies can be up to 10^9. int count_ones = 0; // Initialize an integer variable count_ones to 0. // This variable will count the number of boxes containing exactly one candy. // Loop N times, once for each box. for (int i = 0; i < N; ++i) { std::cin >> C_i; // Read the number of candies for the i-th box. // Check if the current box contains exactly 1 candy. if (C_i == 1) { count_ones++; // If it contains exactly 1 candy, increment the counter. } } // The winning strategy depends on the parity of the number of boxes with exactly 1 candy. // This is based on the analysis that player B has more control over the game state, // particularly regarding the parity of the count of 1-candy boxes. // B can often force the parity to be even on A's turn if it starts even. // A wins if and only if the initial count of 1-candy boxes is odd. // Check if the count of boxes with 1 candy is odd. if (count_ones % 2 != 0) { // If count_ones is odd, Player A (the first player) wins. std::cout << "A" << std::endl; // Output 'A' followed by a newline. } else { // If count_ones is even (including 0), Player B (the second player) wins. std::cout << "B" << std::endl; // Output 'B' followed by a newline. } return 0; // Return 0 to indicate successful execution of the program. }