No.990 N×Mマス計算(Kの倍数)
タグ : / 解いたユーザー数 185
作問者 :
%20
/ テスター :
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. Show the original
Problem Statement
There is a grid with $N$ rows and $M$ columns.
The cell in the $i$-th row from the top and the $j$-th column from the left is called "cell $(i,j)$".
$A_i$ is written to the left of cell $(i,1)$, and $B_j$ is written above cell $(1,j)$.
In cell $(i,j)$, write the result of computing $A_i\ op\ B_j$. Let this value be $C_{i,j}$.
Here, $op$ is either + or *.
If $op$ is +, then $C_{i,j}=A_i+B_j$; if it is *, then $C_{i,j}=A_i\times B_j$.
Find the number of cells $(i,j)$ such that $C_{i,j}$ is a multiple of $K$.
Input
$N$ $M$ $K$ $op$ $B_1$ $B_2$ $\cdots$ $B_M$ $A_1$ $A_2$ $\vdots$ $A_N$
The input satisfies the following constraints.
- $1\le N\le10^5$
- $1\le M\le10^5$
- $1\le K\le10^9$
- $1\le A_i\le10^9$
- $1\le B_j\le10^9$
- $N,M,K,A_i,B_j$ are integers
- $op$ is either
+or*
Output
Output the number of cells $(i,j)$ such that $C_{i,j}$ is a multiple of $K$.
Sample
Sample 1
Input
3 4 13 + 5 12 6 13 8 27 3
Output
2
The grid is filled in as follows.
$\begin{array}{c|c|} + & 5 & 12 & 6 & 13 \\\hline 8 & 13 & 20 & 14 & 21 \\\hline 27 & 32 & 39 & 33 & 40 \\\hline 3 & 8 & 15 & 9 & 16 \\\hline \end{array}$
Sample 2
Input
3 4 12 * 5 12 6 13 8 27 3
Output
4
The grid is filled in as follows.
$\begin{array}{c|c|} * & 5 & 12 & 6 & 13 \\\hline 8 & 40 & 96 & 48 & 104 \\\hline 27 & 135 & 324 & 162 & 351 \\\hline 3 & 15 & 36 & 18 & 39 \\\hline \end{array}$
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。