結果

問題 No.1991 Secret Garden
ユーザー qwewe
提出日時 2025-05-14 13:11:34
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,263 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 67,844 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-05-14 13:13:18
合計ジャッジ時間 1,361 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream> // Include the necessary header for input/output stream operations

int main() {
    // Optional: Speed up C++ I/O operations. These lines can potentially speed up input/output,
    // especially for larger inputs, but might not be necessary for this problem with a single input value.
    // std::ios_base::sync_with_stdio(false); // Disable synchronization with C standard I/O library
    // std::cin.tie(NULL); // Untie cin from cout, potentially allowing input and output operations to not wait for each other

    // Declare a variable N of type long long. This is necessary because the input N
    // can be as large as 10^12, which exceeds the range of a standard 32-bit integer.
    // `long long` in C++ is typically a 64-bit integer type.
    long long N; 
    
    // Read the value of N from standard input.
    std::cin >> N;
    
    // Calculate the maximum number of hidden flowers.
    // Through analysis and testing small cases, we found a pattern suggesting that the minimum number of visible flowers
    // (those visible from at least one balcony) is floor(N/2) + 1.
    // The maximum number of hidden flowers is then N - (minimum visible flowers).
    // Max hidden = N - (floor(N/2) + 1).
    // This expression simplifies based on parity of N:
    // If N is even, N = 2m: Max hidden = 2m - (m + 1) = m - 1 = N/2 - 1.
    // If N is odd, N = 2m + 1: Max hidden = (2m + 1) - (m + 1) = m = (N-1)/2.
    // Both cases can be unified by the single formula floor((N-1)/2).
    //
    // In C++, integer division `(N - 1) / 2` computes floor((N-1)/2) correctly
    // because N >= 2 implies (N-1) >= 1, which is non-negative. Integer division truncates towards zero,
    // which is equivalent to the floor function for positive results.
    long long max_hidden_flowers = (N - 1) / 2;
    
    // Print the calculated maximum number of hidden flowers to standard output.
    // `std::endl` inserts a newline character and flushes the output buffer, ensuring the output
    // is displayed immediately and meets the problem requirement of ending with a newline.
    std::cout << max_hidden_flowers << std::endl;
    
    // Return 0 from the main function to indicate that the program executed successfully.
    return 0;
}
0