CF #420 A. Okabe and Future Gadget Laboratory

向右看齐 2022-06-13 06:27 212阅读 0赞

A. Okabe and Future Gadget Laboratory

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 ≤ x, y ≤ n and a**x, y ≠ 1, there should exist two indices s and t so that a**x, y = a**x, s + a**t, y, where a**i, j denotes the integer in i-th row and j-th column.

Help Okabe determine whether a given lab is good!

Input

The first line of input contains the integer n (1 ≤ n ≤ 50) — the size of the lab.

The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is a**i, j (1 ≤ a**i, j ≤ 105).

Output

Print “Yes” if the given lab is good and “No” otherwise.

You can output each letter in upper or lower case.

Examples

input

  1. 3
  2. 1 1 2
  3. 2 3 1
  4. 6 4 1

output

  1. Yes

input

  1. 3
  2. 1 5 2
  3. 1 1 1
  4. 1 2 3

output

  1. No

Note

In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is “Yes”.

In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is “No”.

思路:循环每个非1数,然后同行 同列进行判定,注意跳过比自己大的数 和自己

  1. #include<iostream>
  2. #include<cstdio>
  3. #define maxn 55
  4. int N;
  5. int a[maxn][maxn];
  6. using namespace std;
  7. int chark(int n, int m, int index) { //以这个数为中心,横竖行进行循环
  8. for(int i = 1; i <= N; i++) {
  9. if(a[i][m] >= index || i == n) //如果此列中 循环到比此数大的话 跳过 循环到自己跳过
  10. continue;
  11. for(int j = 1; j <= N; j++) {
  12. if(a[n][j] >= index || j == m) //同上
  13. continue;
  14. if(a[i][m] + a[n][j] == index) //判定是否成功
  15. return 1;
  16. }
  17. }
  18. return 0;
  19. }
  20. int main () {
  21. scanf("%d", &N);
  22. for(int i = 1; i <= N; i++)
  23. for(int j = 1; j <= N; j++)
  24. scanf("%d", &a[i][j]); //输入二维数组中
  25. for(int i = 1; i <= N; i++) {
  26. for(int j = 1; j <= N; j++) {
  27. if(a[i][j] != 1) { //如果是1 的话跳过
  28. int index = chark(i, j, a[i][j]);
  29. if(index == 0) { //有一个不符合直接结束
  30. printf("No\n");
  31. return 0;
  32. }
  33. }
  34. }
  35. }
  36. printf("Yes\n");
  37. return 0;
  38. }

发表评论

表情:
评论列表 (有 0 条评论,212人围观)

还没有评论,来说两句吧...

相关阅读

    相关 CF1197A

    CF1197A 题意: > 定义k阶梯子为两边各一块木板长度至少k+1,中间k块木板至少为1 。问 给你n块木板,最多能搭成几阶的梯子。 解法: >...

    相关 CF1200A

    CF1200A 解法: > 给出长度为n的字符串,字符串由'L'、'R'以及数字0~9组成。旅馆有10间房子,L代表客人从左边入住,R代表客人从右边入住,数...

    相关 CF1081A

    CF1081A > 题意: > > > 从 ? 开始每次减去一个不是 ?的约数的数,问最小能得到多少? > > 做法: > > > 因为 $ n $ 一