問題一覧 > 通常問題

No.2631 Rectangle Grid Game

レベル : / AI推定難易度 : 2700 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 49
作問者 : kenken714 / テスター : ebi_fly noya2 👑 potato167
お気に入りにしたユーザー ProblemId : 10658 / 自分の提出
問題文最終更新日: 2024-02-15 23:33:31
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
traP 作問ハッカソンコンテスト 002(day1) (順位表) の他の問題:

Problem Statement

Two players, Alice and Bob, are going to play a game of claiming territory on a grid.

You are given a grid with $H$ rows and $W$ columns. Here, the top-left cell is $(1, 1)$ and the bottom-right cell is $(H, W)$.

In the initial state, Alice's and Bob's pieces are placed on cells $(X_A, Y_A), (X_B, Y_B)$ ($(X_A,Y_A)\neq(X_B,Y_B)$), respectively.

Also, cell $(X_A, Y_A)$ is Alice's territory, cell $(X_B, Y_B)$ is Bob's territory, and all other cells belong to neither player's territory.

Alice goes first, and the players take turns alternately. On their turn, a player performs the following operations in the order shown.

  1. Let $(X, Y)$ be the cell where the player's own piece is currently located. Choose a cell $(X^\prime, Y^\prime)$ that satisfies condition $(*)$ and is either the player's own territory or neither player's territory.
  2. $(*)$ The rectangular region having cell $(X, Y)$ and cell $(X^\prime, Y^\prime)$ as the ends of one of its diagonals contains no cell that is the opponent's territory.
    Formally, for all integers $i$, $j$ satisfying $\min(X, X^\prime) \le i \le \max(X, X^\prime)$ , $\min(Y, Y^\prime) \le j \le \max(Y, Y^\prime)$, cell $(i, j)$ is not the opponent's territory.
  3. Move the player's own piece to $(X^\prime, Y^\prime)$.
  4. Make all cells in the rectangular region specified in $(*)$ the player's own territory.

The game ends when Bob's $10^{100}$-th turn is finished.

At the end of the game, the player with more cells in their territory wins. If both players have the same number of such cells, the game is a draw.

Find the number of tuples of variables $(X_A, Y_A, X_B, Y_B)$, which give the initial positions of the cells, such that Alice wins when both players play optimally.

Since this number can be very large, find it modulo $998,244,353$.

Constraints

  • $2 \le H \le 10^9$
  • $2 \le W \le 10^9$
  • All values given in the input are integers

Input

The input is given in the following format.
$H$ $W$

Output

Print the number of tuples of variables in question, modulo $998,244,353$. Print a newline at the end.

Sample

Sample 1
Input
3 4
Output
94

For example, when $(X_A, Y_A, X_B, Y_B) = (1, 1, 3, 4)$, suppose the game proceeds as follows:

  • Alice moves to cell $(2, 3)$
  • Bob moves to cell $(3, 1)$
  • Alice moves to cell $(1, 4)$
Then Alice has $8$ cells of territory and Bob has $4$ cells of territory, so Alice wins.
Considering all other cases as well, there are $94$ tuples of variables in total for which Alice wins.

Sample 2
Input
2 2
Output
0

The game is a draw regardless of the initial state.

Sample 3
Input
3141 5926
Output
428758522

Print the answer modulo $998,244,353$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。