CF1338E.JYPnation

普及/提高-

通过率:0%

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 ABA\neq B .

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

输入格式

The first line contains a single integer nn ( 4n80004 \le n \le 8000 , n0(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.

输出格式

Output one integer, representing the sum of dis(A,B)dis(A,B) over all ordered pairs of cities (A,B)(A,B) with ABA\neq 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 .

首页