Codeforces 463C Gargari and Bishops【模拟】

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 get x 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 integers aij (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), where xi is the number of the row where the i-th bishop should be placed, yi is the number of the column where the i-th bishop should be placed. Consider rows are numbered from 1 to n from top to bottom, and columns are numbered from 1 to n from left to right.

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

Examples
Input
4
1 1 1 1
2 1 1 0
1 1 1 0
1 0 0 1
Output
12
2 2 3 2

题目大意:

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

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


思路:


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


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


#include<stdio.h>
#include<string.h>
using namespace std;
#define ll __int64
#define mid 3000
ll 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值