CF1338E.JYPnation

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Due to the success of TWICE, JYP Entertainment has earned countless money and emerged as the biggest entertainment firm by market capitalization. Therefore, the boss, JYP, has decided to create a new nation and has appointed you to provide a design diagram.

The new nation consists of nn cities and some roads between them. JYP has given some restrictions:

  • To guarantee efficiency while avoiding chaos, for any 22 different cities AA and BB, there is exactly one road between them, and it is one-directional. There are no roads connecting a city to itself.

  • The logo of rivaling companies should not appear in the plan, that is, there does not exist 44 distinct cities AA,BB,CC,DD , such that the following configuration occurs.

JYP has given criteria for your diagram. For two cities AA,BB, let dis(A,B)dis(A,B) be the smallest number of roads you have to go through to get from AA to BB. If it is not possible to walk from AA to BB, dis(A,B)=614ndis(A,B) = 614n. Then, the efficiency value is defined to be the sum of dis(A,B)dis(A,B) for all ordered pairs of distinct cities (A,B)(A,B).

Note that dis(A,B)dis(A,B) doesn't have to be equal to dis(B,A)dis(B,A).

You have drawn a design diagram that satisfies JYP's restrictions. Find the sum of dis(A,B)dis(A,B) over all ordered pairs of cities (A,B)(A,B) with A≠BA\neq B.

Note that the input is given in compressed form. But even though it is compressed, you'd better use fast input.

由于TWICE的成功,JYP娱乐公司已赚取了巨额财富,并一跃成为市值最高的娱乐公司。因此,老板JYP决定创建一个新国家,并任命你为其提供一份设计图。

该新国家由 nn 座城市及它们之间的一些道路组成。JYP给出了如下限制条件:

  • 为保障效率并避免混乱,对任意两个不同的城市 AA 和 BB,其间恰好存在一条单向道路;不存在从某城市通往其自身的道路。

  • 设计图中不得出现竞争对手公司的标志,即:不存在四个互不相同的城市 AA、BB、CC、DD,使得如下构型出现:

JYP还为你的设计图设定了评估标准。对任意两座城市 AA、BB,定义 dis(A,B)dis(A,B) 为从 AA 到 BB 所需经过的最少道路条数;若无法从 AA 到达 BB,则令 dis(A,B)=614ndis(A,B) = 614n。于是,效率值被定义为所有满足 A≠BA \neq B 的有序城市对 (A,B)(A,B) 对应的 dis(A,B)dis(A,B) 之和。

注意:dis(A,B)dis(A,B) 不一定等于 dis(B,A)dis(B,A)。

你已绘制出一幅满足JYP全部限制条件的设计图。请计算所有满足 A≠BA \neq B 的有序城市对 (A,B)(A,B) 对应的 dis(A,B)dis(A,B) 之和。

注意:输入以压缩形式给出。尽管如此,你仍应使用快速输入方式。

输入格式

The first line contains a single integer nn (4≤n≤80004 \le n \le 8000, n≡0(mod4)n \equiv 0 \pmod{4}) — the number of cities.

A binary matrix is encrypted in the following format. Each of nn next lines contains n4\frac{n}{4} one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 00 to 99 or as uppercase Latin letters from AA to FF). Binary representation of each of these numbers denotes next 44 elements of the matrix in the corresponding row. For example, if the number BB is given, then the corresponding elements are 10111011, and if the number is 55, then the corresponding elements are 01010101.

After you obtain the decrypted binary matrix, the jj-th character of the ii-th row is 11 if the one-directional road between cities ii and jj is directed from ii to jj, and 00 otherwise. It is guaranteed that the graph satisfies the restrictions mentioned above.

第一行包含一个整数 nn(4≤n≤80004 \le n \le 8000,且 n≡0(mod4)n \equiv 0 \pmod{4}),表示城市的数量。

接下来以如下格式给出一个二进制矩阵:随后的 nn 行中,每行包含 n4\frac{n}{4} 个一位十六进制数字(即这些数字可表示为数字 00 至 99 或大写拉丁字母 AA 至 FF)。每个十六进制数字的二进制表示对应矩阵中该行的接下来 44 个元素。例如,若给出数字 BB,则对应的四个元素为 10111011;若给出数字 55,则对应的四个元素为 01010101。

在你解密得到该二进制矩阵后,第 ii 行的第 jj 个字符为 11 当且仅当存在一条从城市 ii 指向城市 jj 的有向道路;否则为 00。题目保证该图满足上述所有限制条件。

输出格式

Output one integer, representing the sum of dis(A,B)dis(A,B) over all ordered pairs of cities (A,B)(A,B) with A≠BA\neq B.

输出一个整数,表示对所有满足 A≠BA\neq B 的有序城市对 (A,B)(A,B) 的 dis(A,B)dis(A,B) 之和。

输入输出样例

  • 输入#1

    4
    7
    2
    1
    4

    输出#1

    7380
  • 输入#2

    8
    7F
    3F
    1F
    0C
    06
    03
    11
    18

    输出#2

    88464

说明/提示

The first example corresponds to the matrix:

0111001000010100\begin{matrix} 0111 \\ 0010 \\ 0001 \\ 0100 \\ \end{matrix}

Which corresponds to this graph:

dis(1,2)=dis(1,3)=dis(1,4)=dis(2,3)=dis(3,4)=dis(4,2)=1dis(1,2)=dis(1,3)=dis(1,4)=dis(2,3)=dis(3,4)=dis(4,2)=1

dis(2,4)=dis(4,3)=dis(3,2)=2dis(2,4)=dis(4,3)=dis(3,2)=2

dis(2,1)=dis(3,1)=dis(4,1)=2456dis(2,1)=dis(3,1)=dis(4,1)=2456

Therefore the answer for the diagram is 73807380.

第一个示例对应如下矩阵:

0111001000010100\begin{matrix} 0111 \\ 0010 \\ 0001 \\ 0100 \\ \end{matrix}

该矩阵对应的图如下:

dis(1,2)=dis(1,3)=dis(1,4)=dis(2,3)=dis(3,4)=dis(4,2)=1dis(1,2)=dis(1,3)=dis(1,4)=dis(2,3)=dis(3,4)=dis(4,2)=1

dis(2,4)=dis(4,3)=dis(3,2)=2dis(2,4)=dis(4,3)=dis(3,2)=2

dis(2,1)=dis(3,1)=dis(4,1)=2456dis(2,1)=dis(3,1)=dis(4,1)=2456

因此,该图的答案为 73807380。

输入解题思路,AI测评打分。不知道怎么写?

首页