QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 256 MB 満点: 100

#2762. 勇敢的 Bitaro

統計

勇敢的比太郎(Bitaro the Brave)正面临着恶魔的挑战。

比太郎准备通过在一个 $H \times W$ 的网格上排列宝石(jewels)、宝珠(orbs)和锭(ingots)并施展魔法来攻击恶魔。从上往下第 $i$ 行($1 \le i \le H$)、从左往右第 $j$ 列($1 \le j \le W$)的方格记作 $(i, j)$。

现在,比太郎在每个方格上都放置了这三种物品中的一种。比太郎即将施展的魔法,其威力取决于宝石、宝珠和锭的排列方式。具体来说,威力等于满足以下条件的四元组整数 $(i, j, k, \ell)$($1 \le i < k \le H, 1 \le j < \ell \le W$)的数量。

条件:比太郎在方格 $(i, j)$ 上放置了宝石,在方格 $(i, \ell)$ 上放置了宝珠,并在方格 $(k, j)$ 上放置了锭。

比太郎想知道魔法的威力。 请编写一个程序,在给定宝石、宝珠和锭的排列方式后,计算比太郎施展的魔法的威力。

输入格式

从标准输入读取以下数据:

$H \ W$ $S_1$ $:$ $S_H$

$S_i$($1 \le i \le H$)是一个长度为 $W$ 的字符串。如果 $S_i$ 的第 $j$ 个字符是 'J',则方格 $(i, j)$($1 \le j \le W$)上放置的是宝石;如果是 'O',则是宝珠;如果是 'I',则是锭。

输出格式

向标准输出打印一行,包含比太郎施展的魔法的威力。

数据范围

  • $2 \le H \le 3\,000$
  • $2 \le W \le 3\,000$
  • $S_i$ 是长度为 $W$ 的字符串($1 \le i \le H$)
  • $S_i$ 的每个字符均为 'J'、'O' 或 'I'($1 \le i \le H$)

子任务

  1. (20 分)$H \le 100, W \le 100$
  2. (30 分)$H \le 500, W \le 500$
  3. (50 分)无附加限制

样例

输入格式 1

3 4
JOIJ
JIOO
IIII

输出格式 1

3

说明

在这个样例中,有 3 个四元组 $(i, j, k, \ell) = (1, 1, 3, 2), (2, 1, 3, 3), (2, 1, 3, 4)$ 满足条件,因此你应该输出 3。

输入格式 2

4 4
JJOO
JJOO
IIJO
IIIJ

输出格式 2

17

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.