This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint_c.h"
#include <string.h>
#define N 200000
#define K 100
int solve(char *aa, int *ll, int n, int k) {
static int dp[N + 1][K + 1], pp[N];
int h, i;
for (i = 0; i < n; i++)
pp[i] = aa[i] == '_' ? i : (i == 0 ? -1 : pp[i - 1]);
for (i = 0; i <= n; i++)
memset(dp[i], 0, (k + 1) * sizeof *dp[i]);
dp[0][0] = 1;
for (i = 1; i <= n; i++)
for (h = 0; h <= k; h++) {
int l = h == 0 ? -1 : ll[h - 1];
dp[i][h] = aa[i - 1] != 'X' && dp[i - 1][h] || h > 0 && pp[i - 1] < i - l && (i == l && h == 1 || aa[i - 1 - l] != 'X' && dp[i - 1 - l][h - 1]);
}
return dp[n][k];
}
void solve_puzzle(int n, char *aa, int k, int *ll, char *cc) {
int i;
for (i = 0; i < n; i++)
cc[i] = aa[i] == '.' ? '?' : aa[i];
for (i = 0; i < n; i++)
if (cc[i] == '?') {
int can_w, can_b;
aa[i] = '_', can_w = solve(aa, ll, n, k);
aa[i] = 'X', can_b = solve(aa, ll, n, k);
aa[i] = '.';
if (!can_w)
cc[i] = 'X';
else if (!can_b)
cc[i] = '_';
}
}
Compilation message (stderr)
paint.c: In function 'solve':
paint.c:20:89: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
20 | dp[i][h] = aa[i - 1] != 'X' && dp[i - 1][h] || h > 0 && pp[i - 1] < i - l && (i == l && h == 1 || aa[i - 1 - l] != 'X' && dp[i - 1 - l][h - 1]);
| ~~~~~~~^~~~~~~~~
paint.c:20:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
20 | dp[i][h] = aa[i - 1] != 'X' && dp[i - 1][h] || h > 0 && pp[i - 1] < i - l && (i == l && h == 1 || aa[i - 1 - l] != 'X' && dp[i - 1 - l][h - 1]);
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |