Submission #878596

#TimeUsernameProblemLanguageResultExecution timeMemory
878596rainboyRobogolf (ROI19_golf)C11
100 / 100
328 ms25260 KiB
#include <stdio.h> #define K 100000 #define N (K * 6) #define MD 998244353 int min(int a, int b) { return a < b ? a : b; } int max(int a, int b) { return a > b ? a : b; } unsigned int Z = 12345; int rand_() { return (Z *= 3) >> 1; } int xx[N], yy[N], dd[N], ww[N], ii[N], dp[N][2], n; char trap[N], visited[N][2]; void sort(int *ii, int l, int r) { while (l < r) { int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp; while (j < k) { int c = dd[ii[j]] != dd[i_] ? dd[ii[j]] - dd[i_] : xx[ii[j]] - xx[i_]; if (c == 0) j++; else if (c < 0) { tmp = ii[i], ii[i] = ii[j], ii[j] = tmp; i++, j++; } else { k--; tmp = ii[j], ii[j] = ii[k], ii[k] = tmp; } } sort(ii, l, i); l = k; } } int solve(int x, int y, int turn) { int d, lower, upper, i; d = x - y; lower = -1, upper = n; while (upper - lower > 1) { i = (lower + upper) / 2; if (dd[ii[i]] < d || dd[ii[i]] == d && xx[ii[i]] < x) lower = i; else upper = i; } if (upper == n || dd[i = ii[upper]] != d) return 0; x = xx[i], y = yy[i]; if (!visited[i][turn]) visited[i][turn] = 1, dp[i][turn] = trap[i] ? ww[i] : (turn == 0 ? min(solve(x + 1, y, 1), solve(x, y + 1, 1)) : max(solve(x + 1, y, 0), solve(x, y + 1, 0))); return dp[i][turn]; } int main() { int n_, k, i, ans; scanf("%*d%*d%d", &k); n = 0; while (k--) { int x, y, w; scanf("%d%d%d", &x, &y, &w); xx[n] = x, yy[n] = y, ww[n] = w, trap[n] = 1, n++; if (x > 1) xx[n] = x - 1, yy[n] = y, ww[n] = 0, n++; if (y > 1) xx[n] = x, yy[n] = y - 1, ww[n] = 0, n++; if (x > 2) xx[n] = x - 2, yy[n] = y, ww[n] = 0, n++; if (x > 1 && y > 1) xx[n] = x - 1, yy[n] = y - 1, ww[n] = 0, n++; if (y > 2) xx[n] = x, yy[n] = y - 2, ww[n] = 0, n++; } for (i = 0; i < n; i++) dd[i] = xx[i] - yy[i]; for (i = 0; i < n; i++) ii[i] = i; sort(ii, 0, n); n_ = 0; for (i = 0; i < n; i++) if (n_ == 0 || xx[ii[n_ - 1]] != xx[ii[i]] || yy[ii[n_ - 1]] != yy[ii[i]]) ii[n_++] = ii[i]; else if (trap[ii[i]]) ii[n_ - 1] = ii[i]; n = n_; ans = 0; for (i = 0; i < n; i++) ans = (ans + (long long) solve(xx[ii[i]], yy[ii[i]], 0) * (i == 0 || dd[ii[i]] != dd[ii[i - 1]] ? min(xx[ii[i]], yy[ii[i]]) : xx[ii[i]] - xx[ii[i - 1]])) % MD; if (ans < 0) ans += MD; printf("%d\n", ans); return 0; }

Compilation message (stderr)

golf.c: In function 'solve':
golf.c:47:39: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   47 |   if (dd[ii[i]] < d || dd[ii[i]] == d && xx[ii[i]] < x)
      |                        ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
golf.c: In function 'main':
golf.c:63:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |  scanf("%*d%*d%d", &k);
      |  ^~~~~~~~~~~~~~~~~~~~~
golf.c:68:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |   scanf("%d%d%d", &x, &y, &w);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...