問題一覧 > 通常問題

No.988 N×Mマス計算(総和)

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 372
作問者 : %20 / テスター : kotatsugame
お気に入りにしたユーザー ProblemId : 3905 / 自分の提出
問題文最終更新日: 2020-02-07 21:01:22
N×M Grid Calculation (Sum)
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
yukicoder contest 237 (順位表) の他の問題:

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 remainder when $\displaystyle \sum_{i=1}^N \sum_{j=1}^M C_{i,j}$ is divided by $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 remainder when $\displaystyle \sum_{i=1}^N \sum_{j=1}^M C_{i,j}$ is divided by $K$.

Sample

Sample 1
Input
3 4 100
+ 5 12 6 13
8
27
3
Output
60

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}$

Since $13+20+14+21+32+39+33+40+8+15+9+16=260$, output $60$, which is the remainder when $260$ is divided by $K=100$.

Sample 2
Input
3 4 100
* 5 12 6 13
8
27
3
Output
68

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}$

Since $40+96+48+104+135+324+162+351+15+36+18+39=1368$, output $68$, which is the remainder when $1368$ is divided by $K=100$.

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