zl程序教程

您现在的位置是:首页 >  其它

当前栏目

【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

and Codeforces div round Future
2023-09-14 09:03:50 时间

【题目链接】:http://codeforces.com/contest/821/problem/A

【题意】

给你一个n*n的数组;
然后问你,是不是每个位置(x,y);
都能找到一个同一行的元素q和同一列的元素w;
使得q+w=a[x][y]

【题解】

O(N4)模拟

【Number Of WA

0

【反思】

不用考虑会选到a[x][y]本身.

【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)

typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 50;

int a[N+10][N+10],n;

void out(){
    cout <<"No"<<endl;
    exit(0);
}

int main(){
    //Open();
    Close();
    cin >> n;
    rep1(i,1,n){
        rep1(j,1,n){
            cin >> a[i][j];
        }
    }
    rep1(i,1,n){
        rep1(j,1,n){
            if (a[i][j]!=1){
                int fi = 0;
                rep1(ii,1,n)
                    rep1(jj,1,n)
                        if (a[ii][j]+a[i][jj]==a[i][j])
                            fi = 1;
                if (!fi) out();
            }
        }
    }
    cout <<"Yes"<<endl;
    return 0;
}