Codeforces 463C Gargari and Bishops【模拟】

来源:互联网 发布:mac vmware 安装win10 编辑:程序博客网 时间:2024/06/04 18:58

C. Gargari and Bishops
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius.

He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of them. Consider a cell with number x written on it, if this cell is attacked by one of the bishops Gargari will getx dollars for it. Tell Gargari, how to place bishops on the chessboard to get maximum amount of money.

We assume a cell is attacked by a bishop, if the cell is located on the same diagonal with the bishop (the cell, where the bishop is, also considered attacked by it).

Input

The first line contains a single integer n(2 ≤ n ≤ 2000). Each of the next n lines contains n integersaij(0 ≤ aij ≤ 109) — description of the chessboard.

Output

On the first line print the maximal number of dollars Gargari will get. On the next line print four integers:x1, y1, x2, y2(1 ≤ x1, y1, x2, y2 ≤ n), wherexi is the number of the row where thei-th bishop should be placed, yi is the number of the column where thei-th bishop should be placed. Consider rows are numbered from 1 ton from top to bottom, and columns are numbered from 1 ton from left to right.

If there are several optimal solutions, you can print any of them.

Examples
Input
41 1 1 12 1 1 01 1 1 01 0 0 1
Output
122 2 3 2

题目大意:

给你一个N*N大小的格子,我们可以在上边放两个棋子,对应获得棋子所在两个对角线的价值,我们现在想要得到一个放置的方式,使得两个棋子没有共同攻击得到的位子存在

问怎样放置能够获得最大值。


思路:


1、思路很好建立,对应我们希望两个棋子没有重叠点,那么我们将图按照坐标(x+y)的奇偶性染成黑白两色。那么我们只要保证一个棋子放在黑色位子上, 另外一个棋子放在白色位子上即可,对应我们想要得到最大价值,那么我们只要每种情况的维护最大值即可。


2、那么我们求出每一种对角线的和,然后对应枚举点,维护最大值加和即可。


#include<stdio.h>#include<string.h>using namespace std;#define ll __int64#define mid 3000ll r[2005*4];ll l[2005*4];ll a[2005][2005];int main(){    int n;    while(~scanf("%d",&n))    {        memset(l,0,sizeof(l));        memset(r,0,sizeof(r));        for(int i=0;i<n;i++)        {            for(int j=0;j<n;j++)            {                scanf("%I64d",&a[i][j]);                l[i+j]+=a[i][j];                r[i-j+mid]+=a[i][j];            }        }        ll ans1=-1,ans2=-1;        int xx,yy,xxx,yyy;        for(int i=0;i<n;i++)        {            for(int j=0;j<n;j++)            {                ll val=r[i-j+mid]+l[i+j]-a[i][j];                if((i+j)%2==0)                {                    if(val>ans1)                    {                        ans1=val;                        xx=i+1,yy=j+1;                    }                }                if((i+j)%2==1)                {                    if(val>ans2)                    {                        ans2=val;                        xxx=i+1,yyy=j+1;                    }                }            }        }        printf("%I64d\n%d %d %d %d\n",ans1+ans2,xx,yy,xxx,yyy);    }}





0 0
原创粉丝点击