Codeforces round #264 (Div. 2) c

Source: Internet
Author: User
Question: C. gargari and bishopstime limit per test3 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard 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 hasN? ×?NChessboard. 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 numberXWritten on it, if this cell is attacked by one of the Bishops gargargari will getXDollars 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 integerN(2? ≤?N? ≤? 2000). Each of the nextNLines containsNIntegersAIJ(0? ≤?AIJ? ≤? 109)-Description of the chessboard.

Output

On the first line print the maximal number of dollars gargargari will get. On the next line Print four integers:X1 ,?Y1 ,?X2 ,?Y2 (1? ≤?X1 ,?Y1 ,?X2 ,?Y2? ≤?N), WhereXIIs the number of the row whereI-Th Bishop shoshould be placed,YIIs the number of the column whereI-Th Bishop shoshould be placed. Consider rows are numbered from 1NFrom top to bottom, and columns are numbered from 1NFrom left to right.

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

Sample test (s) Input
41 1 1 12 1 1 01 1 1 01 0 0 1
Output
122 2 3 2


Question Analysis:

Here is an N * n grid. Each grid has a value! Put two bishops on a grid. Each Bishop can attack the grid on the diagonal line (the diagonal line of the main line and the diagonal line of the person), and then obtain the value on the grid (only once ). The maximum values obtained by two bishops and their locations must be output!

Idea: brute force. First, we all know that the horizontal and vertical coordinates on each primary diagonal line are the same, and the horizontal and vertical coordinates on each diagonal line are the same! Then we can calculate the sum of all the values on the diagonal line during input. Finally, we find that if we want to obtain the maximum value, another one is that the diagonal lines of the two bishops cannot overlap on the same grid. Only the sum of the two bishops ordinate values is equal to or even to each other. Find the sum of X and Y coordinates in all the grids and obtain the largest number of grids and Y coordinates on the diagonal line and the even number and obtain the largest number of grids on the diagonal line. The sum of the maximum obtained values is the final answer. There is no good idea for the competition. Now let's make up. Very good questions



Code:
# Include <iostream> # include <cstring> # include <cstdio> # include <algorithm> # define n 2005 using namespace STD; typedef long ll; int num [N] [N]; ll sumn [N * 2], Summ [N * 2]; int N; int main () {While (scanf ("% d", & N )! = EOF) {memset (sumn, 0, sizeof (sumn); memset (Summ, 0, sizeof (summ); For (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= N; ++ J) {scanf ("% d", & num [I] [J]); sumn [I + J] + = num [I] [J]; // The sum of the abscissa and ordinate coordinates is the diagonal value of I + J and the value of summ [I-j + N] + = num [I] [J]; // The deviation between x and y coordinates is the diagonal value of I-j and} ll max1 =-1, max2 =-1, s; int x1, x2, Y1, Y2; for (INT I = 1; I <= N; ++ I) for (Int J = 1; j <= N; ++ J) {If (I + J) & 1) {If (max1 <(S = sumn [I + J] + summ [I-j + N]-num [I] [J]) {max1 = s; // The sum of the x-axis and Y-axis is an odd number, and the largest grid X1 = I; Y1 = J ;}} on the diagonal is obtained ;}} else {If (max2 <(S = sumn [I + J] + summ [I-j + N]-num [I] [J]) {max2 = s; // The sum of the x-axis and Y-axis is an even number and obtains the largest grid X2 = I; y2 = J ;}} printf ("% LLD \ n", max1 + max2) on the diagonal line ); printf ("% d \ n", X1, Y1, X2, Y2);} return 0 ;}



Codeforces round #264 (Div. 2) c

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.