CF632F.Magic Matrix

提高+/省选-

通过率:0%

时间限制:5.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You're given a matrix A of size n × n.

Let's call the matrix with nonnegative elements magic if it is symmetric (so a__ij = a__ji), a__ii = 0 and a__ij ≤ max(a__ik, a__jk) for all triples i, j, k. Note that i, j, k do not need to be distinct.

Determine if the matrix is magic.

As the input/output can reach very huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java.

给你一个大小为 n×nn \times n 的矩阵 AA。

我们称一个所有元素均为非负数的矩阵为魔法矩阵,当且仅当它满足以下条件:

  • 对称(即对所有 i,ji,j 有 aij=ajia_{ij} = a_{ji});
  • 所有对角线元素为零(即对所有 ii 有 aii=0a_{ii} = 0);
  • 对任意三元组 i,j,ki, j, k(i,j,ki, j, k 可以不互异),均有 aij≤max⁡(aik, ajk)a_{ij} \le \max(a_{ik},\, a_{jk})。

请判断给定矩阵是否为魔法矩阵。

由于输入/输出规模可能极大,建议使用快速输入/输出方式:例如,在 C++ 中优先使用 scanf/printf 而非 cin/cout;在 Java 中优先使用 BufferedReader/PrintWriter 而非 Scanner/System.out。

输入格式

The first line contains integer n (1 ≤ n ≤ 2500) — the size of the matrix A.

Each of the next n lines contains n integers a__ij (0 ≤ a__ij < 109) — the elements of the matrix A.

Note that the given matrix not necessarily is symmetric and can be arbitrary.

第一行包含一个整数 nn(1≤n≤25001 \leq n \leq 2500)——矩阵 AA 的大小。

接下来的 nn 行,每行包含 nn 个整数 aija_{ij}(0≤aij<1090 \leq a_{ij} < 10^9)——矩阵 AA 的元素。

注意:给定的矩阵不一定对称,可以是任意矩阵。

输出格式

Print ''MAGIC" (without quotes) if the given matrix A is magic. Otherwise print ''NOT MAGIC".

如果给定矩阵 AA 是幻方,则输出 MAGIC''(不带引号);否则输出 NOT MAGIC''。

输入输出样例

  • 输入#1

    3
    0 1 2
    1 0 2
    2 2 0

    输出#1

    MAGIC
  • 输入#2

    2
    0 1
    2 3

    输出#2

    NOT MAGIC
  • 输入#3

    4
    0 1 2 3
    1 0 3 4
    2 3 0 5
    3 4 5 0

    输出#3

    NOT MAGIC

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

首页