C. Magic Odd Square

Codeforces
IDCF710C
Time1000ms
Memory256MB
Difficulty
constructive algorithmsmath
English · Original
Chinese · Translation
Formal · Original
Find an _n_ × _n_ matrix with different numbers from 1 to _n_2, so the sum in each row, column and both main diagonals are odd. ## Input The only line contains odd integer _n_ (1 ≤ _n_ ≤ 49). ## Output Print _n_ lines with _n_ integers. All the integers should be different and from 1 to _n_2. The sum in each row, column and both main diagonals should be odd. [samples]
请构造一个 #cf_span[n × n] 的矩阵,其中包含从 #cf_span[1] 到 #cf_span[n2] 的不同整数,使得每一行、每一列以及两条主对角线的交错和均为奇数。 输入仅一行,包含一个奇整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 49])。 请输出 #cf_span[n] 行,每行包含 #cf_span[n] 个整数。所有整数必须互不相同,且范围在 #cf_span[1] 到 #cf_span[n2] 之间。每行、每列以及两条主对角线的交错和都必须为奇数。 ## Input 输入仅一行,包含一个奇整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 49])。 ## Output 请输出 #cf_span[n] 行,每行包含 #cf_span[n] 个整数。所有整数必须互不相同,且范围在 #cf_span[1] 到 #cf_span[n2] 之间。每行、每列以及两条主对角线的交错和都必须为奇数。 [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be an odd integer with $ 1 \leq n \leq 49 $. Let $ A = (a_{i,j}) \in \mathbb{Z}^{n \times n} $ be an $ n \times n $ matrix. **Constraints** 1. The entries of $ A $ are a permutation of $ \{1, 2, \dots, n^2\} $. 2. For each row $ i \in \{1, \dots, n\} $: $ \sum_{j=1}^n a_{i,j} $ is odd. 3. For each column $ j \in \{1, \dots, n\} $: $ \sum_{i=1}^n a_{i,j} $ is odd. 4. The main diagonal sum: $ \sum_{i=1}^n a_{i,i} $ is odd. 5. The anti-diagonal sum: $ \sum_{i=1}^n a_{i,n+1-i} $ is odd. **Objective** Construct such a matrix $ A $.
Samples
Input #1
1
Output #1
1
Input #2
3
Output #2
2 1 4
3 5 7
6 9 8
API Response (JSON)
{
  "problem": {
    "name": "C. Magic Odd Square",
    "description": {
      "content": "Find an _n_ × _n_ matrix with different numbers from 1 to _n_2, so the sum in each row, column and both main diagonals are odd.",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF710C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Find an _n_ × _n_ matrix with different numbers from 1 to _n_2, so the sum in each row, column and both main diagonals are odd.\n\n## Input\n\nThe only line contains odd integer _n_ (1 ≤ _n_ ≤ 49).\n\n## Ou...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "请构造一个 #cf_span[n × n] 的矩阵,其中包含从 #cf_span[1] 到 #cf_span[n2] 的不同整数,使得每一行、每一列以及两条主对角线的交错和均为奇数。\n\n输入仅一行,包含一个奇整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 49])。\n\n请输出 #cf_span[n] 行,每行包含 #cf_span[n] 个整数。所有整数必须互不相同,且范围在 #...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be an odd integer with $ 1 \\leq n \\leq 49 $.  \nLet $ A = (a_{i,j}) \\in \\mathbb{Z}^{n \\times n} $ be an $ n \\times n $ matrix.\n\n**Constraints**  \n1. The entri...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments