아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Arithmetic Square

메모리 제한1024 MB

요약
3x3 격자의 가운데 빈칸을 임의의 정수로 채워 8개의 행, 열, 대각선 중 등차수열이 되는 개수를 최대로 만든다.
난이도

보통10점 중 4점

유형
수학, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

You are given a 3×3 grid of integers. Let Gi,j denote the integer in the i-th row and j-th column of the grid, where i and j are 0-indexed. The integer in the middle of the grid, G1,1, is missing. Find the maximum number of rows, columns, and diagonals of this square, that form sequences which are arithmetic progressions. You can replace the missing number with any integer.

An arithmetic progression (also known as arithmetic sequence) is a sequence of numbers such that the difference between consecutive terms is constant. In mathematical terms, this can be represented as an=an−1+d, where d is the common difference. In this problem, a sequence can be the 3 numbers in either a row, column or diagonal. We are looking to replace the missing value by an integer that maximizes the number of arithmetic progressions that can be found in the resulting set of sequences.

Two sequences are considered different if they are from different rows, columns, or diagonals. For example, the sequence {2,4,6} across the middle row and {2,4,6} across the top row will be counted as two sequences but the sequences {2,4,6} and {6,4,2} across the same row, column, or diagonal will be counted as one sequence.

입력

The first line of the input gives the number of test cases, T. T test cases follow.

Each test case consists of 3 lines.

The first line of each test case contains 3 integers, G0,0, G0,1, and G0,2.

The second line of each test case contains 2 integers, G1,0 and G1,2.

The last line of each test case contains 3 integers, G2,0, G2,1, and G2,2.

출력

For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is the maximum possible number of arithmetic progressions that can be generated by the rows, columns, and diagonals of the grid after setting the missing element.

제한

  • 1 ≤ T ≤ 100.
  • Gi,j are integers, for all i,j.

힌트

In Sample Case #1, if we set the missing number to be 5, we have exactly 4 arithmetic progressions.

  • top left diagonal: [3,5,7]
  • top right diagonal: [−1,5,11]
  • middle column: [4,5,6]
  • right column: [11,9,7]

If we set the missing number to any other integer, there would be only 1 progression. Thus, the answer is 4.

In Sample Case #2, if we set the missing number to be 4, we have exactly 3 arithmetic progressions.

  • top right diagonal: [6,4,2]
  • middle row: [3,4,5]
  • left column: [4,3,2]

Setting the missing number to any other integer results in fewer progressions, so we output 3.

In Sample Case #3, if we set the missing number to be 9, we have all possible arithmetic progressions. There are 8 total progressions (each one is [9,9,9]), so we output 8.

예제1

  1. 예제 1

    입력
    3
    3 4 11
    10 9
    -1 6 7
    4 1 6
    3 5
    2 5 6
    9 9 9
    9 9
    9 9 9
    
    예상 출력
    Case #1: 4
    Case #2: 3
    Case #3: 8