CF1205C.Palindromic Paths

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem

You are given a grid n×nn\times n, where nn is odd. Rows are enumerated from 11 to nn from up to down, columns are enumerated from 11 to nn from left to right. Cell, standing on the intersection of row xx and column yy, is denoted by (x,y)(x, y).

Every cell contains 00 or 11. It is known that the top-left cell contains 11, and the bottom-right cell contains 00.

We want to know numbers in all cells of the grid. To do so we can ask the following questions:

"?? x1x_1 y1y_1 x2x_2 y2y_2", where 1≤x1≤x2≤n1 \le x_1 \le x_2 \le n, 1≤y1≤y2≤n1 \le y_1 \le y_2 \le n, and x1+y1+2≤x2+y2x_1 + y_1 + 2 \le x_2 + y_2. In other words, we output two different cells (x1,y1)(x_1, y_1), (x2,y2)(x_2, y_2) of the grid such that we can get from the first to the second by moving only to the right and down, and they aren't adjacent.

As a response to such question you will be told if there exists a path between (x1,y1)(x_1, y_1) and (x2,y2)(x_2, y_2), going only to the right or down, numbers in cells of which form a palindrome.

For example, paths, shown in green, are palindromic, so answer for "?? 11 11 22 33" and "?? 11 22 33 33" would be that there exists such path. However, there is no palindromic path between (1,1)(1, 1) and (3,1)(3, 1).

Determine all cells of the grid by asking not more than n2n^2 questions. It can be shown that the answer always exists.

这是一个交互式问题。

给定一个 n×nn\times n 的网格,其中 nn 为奇数。行从上到下编号为 11 到 nn,列从左到右编号为 11 到 nn。位于第 xx 行、第 yy 列的格子记作 (x,y)(x, y)。

每个格子中包含数字 00 或 11。已知左上角格子 (1,1)(1,1) 中为 11,右下角格子 (n,n)(n,n) 中为 00。

我们的目标是确定网格中所有格子内的数字。为此,你可以提出如下形式的问题:

“?? x1x_1 y1y_1 x2x_2 y2y_2”,其中 1≤x1≤x2≤n1 \le x_1 \le x_2 \le n,1≤y1≤y2≤n1 \le y_1 \le y_2 \le n,且满足 x1+y1+2≤x2+y2x_1 + y_1 + 2 \le x_2 + y_2。换言之,你输出网格中两个不同的格子 (x1,y1)(x_1, y_1) 和 (x2,y2)(x_2, y_2),使得仅通过向右或向下移动即可从第一个格子到达第二个格子,且这两个格子不相邻。

对于该问题,系统将返回:是否存在一条仅向右或向下移动、连接 (x1,y1)(x_1, y_1) 与 (x2,y2)(x_2, y_2) 的路径,使得该路径上所有格子中的数字构成一个回文串。

例如,图中以绿色标出的路径均为回文路径,因此对问题 “?? 11 11 22 33” 和 “?? 11 22 33 33” 的回答均为“存在这样的路径”。然而,在 (1,1)(1,1) 与 (3,1)(3,1) 之间并不存在回文路径。

请通过不超过 n2n^2 次提问,确定网格中所有格子的数值。可以证明答案恒存在。

输入格式

The first line contains odd integer (3≤n<503 \le n \lt 50) — the side of the grid.

第一行包含一个奇数整数(3≤n<503 \le n \lt 50)——网格的边长。

输入输出样例

  • 输入#1

    3
    0
    1
    0
    1
    1
    1
    1

    输出#1

    ? 1 1 1 3
    ? 1 1 2 3
    ? 2 1 2 3
    ? 3 1 3 3
    ? 2 2 3 3
    ? 1 2 3 2
    ? 1 2 3 3
    !
    100
    001
    000

输入解题思路,AI测评打分。不知道怎么写?

首页