Codeforces Round #420 (Div. 2)总结

123 篇文章 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 byn 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 ax, y ≠ 1, there should exist two indices s and t so that ax, y = ax, s + at, y, where ai, 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 ai, j (1 ≤ ai, 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
3
1 1 2
2 3 1
6 4 1
output
Yes
input
3
1 5 2
1 1 1
1 2 3
output
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的aij。是否在第i行和第j列各找一个数,使他们的和==aij。 

解:暴力判断

import java.util.Scanner;

/**
 * 
 * 作者:张宇翔 创建日期:2017年6月19日 上午9:37:18 描述:
 */
public class Main {


	private static final int Max=(int) (1e2+10);
	private static int n;
	private static int a[][];
	public static void main(String[] args) {
		InitData();
		GetAns();
	}
	private static void InitData(){
		Scanner cin=new Scanner(System.in);
		n=cin.nextInt();
		a=new int[Max][Max];
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				a[i][j]=cin.nextInt();
			}
		}
	};
	private static void GetAns(){
		boolean ok=true;
		for(int x=0;x<n;x++){
			for(int y=0;y<n;y++){
				if(a[x][y]!=1){
					boolean flag=false;
					for(int s=0;s<n;s++){
						for(int t=0;t<n;t++){
							if(y!=s&&x!=t){
								if(a[x][y]==a[x][s]+a[t][y]){
									flag=true;
								}
							}
						}
					}
					if(!flag){
						ok=false;
					}
				}
			}
		}
		if(ok){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	};
}

B. Okabe and Banana Trees
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.

Consider the point (x, y) in the 2D plane such that x and y are integers and 0 ≤ x, y. There is a tree in such a point, and it has x + ybananas. There are no trees nor bananas in other points. Now, Okabe draws a line with equation . Okabe can select a single rectangle with axis aligned sides with all points on or under the line and cut all the trees in all points that are inside or on the border of this rectangle and take their bananas. Okabe's rectangle can be degenerate; that is, it can be a line segment or even a point.

Help Okabe and find the maximum number of bananas he can get if he chooses the rectangle wisely.

Okabe is sure that the answer does not exceed 1018. You can trust him.

Input

The first line of input contains two space-separated integers m and b (1 ≤ m ≤ 10001 ≤ b ≤ 10000).

Output

Print the maximum number of bananas Okabe can get from the trees he cuts.

Examples
input
1 5
output
30
input
2 3
output
25
Note

The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas.


题意:在所给的直线和第一象限所围成的图形中,找到贡献最大的矩形(可退化)。贡献:矩形中,所有点的行列和。 
解:因为y轴最大为1000,所以o(b^2)枚举起点和终点,根据直线算出矩形的长,前缀和计算贡献,维护最大值。 

import java.util.Scanner;

/**
 * 
 * 作者:张宇翔 创建日期:2017年6月19日 上午9:37:18 描述:
 */
public class Main {


	private static final int Max=(int) (1e2+10);
	private static long m,b;
	public static void main(String[] args) {
		InitData();
		GetAns();
	}
	private static void InitData(){
		Scanner cin=new Scanner(System.in);
		m=cin.nextLong();
		b=cin.nextLong();
	};
	private static void GetAns(){
		long x=b*m;
		long y=b;
		long ans=0;
		for(long i=x;i>=0;i--){
			if(i%m==0){
				long j=b-(i/m);
				long temp=(j+1)*(j*(i+1)+((i+1)*i)/2)-(j+(j*(j-1))/2)*(i+1);
				ans=Math.max(temp, ans);
			}
		}
		System.out.println(ans);
	};
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值