Submission #1128693

#TimeUsernameProblemLanguageResultExecution timeMemory
1128693jackofall718Kamenčići (COCI21_kamencici)C++20
Compilation error
0 ms0 KiB
#include <cstdio>  // Include the C standard I/O header for input and output functions

const int MAXN = 352;  // Define a constant MAXN for the maximum size of the array plus 2
int n, k, prefix[MAXN], dp[MAXN][MAXN][MAXN];  // Declare global variables for number of pebbles (n), red pebbles to avoid (k), prefix sums, and the DP table

int can_win(int l, int r, int uk) {  // Define a function to determine if the current player can force a win
    int& res = dp[l][r][uk];  // Reference to the DP table entry for current state for easier access and modification
    if (res != -1) return res;  // If this state has already been calculated, return the stored result

    int total_red = prefix[n-1];  // Calculate the total number of red pebbles in the entire array
    int red_left = prefix[r] - (l ? prefix[l-1] : 0);  // Calculate the number of red pebbles in the subarray [l, r]
    int other_red = total_red - red_left - uk;  // Calculate how many red pebbles the opponent has based on the total, the interval, and the current player's count

    if (uk >= k) return res = 0;  // If the current player has collected k or more red pebbles, they lose (return 0)
    if (other_red >= k) return res = 1;  // If the opponent has collected k or more red pebbles, they lose (current player wins, return 1)

    return res = !can_win(l+1, r, other_red) || !can_win(l, r-1, other_red);  // Recur for the next states by removing one pebble from either end, check if any move forces a win
}

int main() {  // Main function to handle input/output and initiate the solution process
    scanf("%d %d %s", &n, &k, prefix);  // Read the number of pebbles, the critical number of red pebbles, and the array of pebbles as a string
    for (int i = 0; i < n; i++) {  // Loop through the pebble string to compute the prefix sum of red pebbles
        prefix[i] = (i ? prefix[i-1] : 0) + (prefix[i] == 'C');  // Accumulate the count of 'C' from the start to the current position
    }
    memset(dp, -1, sizeof(dp));  // Initialize the DP table with -1 indicating that no state has been computed yet
    puts(can_win(0, n-1, 0) ? "DA" : "NE");  // Determine if Antun can force a win starting from the full range of pebbles with no red pebbles collected and print the result
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:21:19: warning: format '%s' expects argument of type 'char*', but argument 4 has type 'int*' [-Wformat=]
   21 |     scanf("%d %d %s", &n, &k, prefix);  // Read the number of pebbles, the critical number of red pebbles, and the array of pebbles as a string
      |                  ~^           ~~~~~~
      |                   |           |
      |                   char*       int*
      |                  %d
Main.cpp:25:5: error: 'memset' was not declared in this scope
   25 |     memset(dp, -1, sizeof(dp));  // Initialize the DP table with -1 indicating that no state has been computed yet
      |     ^~~~~~
Main.cpp:2:1: note: 'memset' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
    1 | #include <cstdio>  // Include the C standard I/O header for input and output functions
  +++ |+#include <cstring>
    2 | 
Main.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%d %d %s", &n, &k, prefix);  // Read the number of pebbles, the critical number of red pebbles, and the array of pebbles as a string
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~