CF1697D.Guess The String

普及+/提高

通过率:0%

时间限制:4.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: https://codeforces.com/blog/entry/45307.

The jury has chosen a string ss consisting of nn characters; each character of ss is a lowercase Latin letter. Your task is to guess this string; initially, you know only its length.

You may ask queries of two types:

  • 11 ii — the query of the first type, where ii is an integer from 11 to nn. In response to this query, the jury will tell you the character sis_i;
  • 22 ll rr — the query of the second type, where ll and rr are integers such that 1≤l≤r≤n1 \le l \le r \le n. In response to this query, the jury will tell you the number of different characters among sl,sl+1,…,srs_l, s_{l+1}, \dots, s_r.

You are allowed to ask no more than 2626 queries of the first type, and no more than 60006000 queries of the second type. Your task is to restore the string ss.

For each test in this problem, the string ss is fixed beforehand, and will be the same for every submission.

这是一个交互式问题。在与评测程序通信时,请务必刷新你的输出。你可以在 C++ 中使用 fflush(stdout),Java 中使用 system.out.flush(),Python 中使用 stdout.flush(),Pascal 中使用 flush(output) 来刷新输出。如果你使用其他编程语言,请查阅其文档。你也可以参考交互式问题指南:https://codeforces.com/blog/entry/45307。

出题人预先选定一个长度为 nn 的字符串 ss;ss 中的每个字符均为小写拉丁字母。你的任务是猜出该字符串;初始时你仅知道其长度。

你可以提出两类查询:

  • 11 ii —— 第一类查询,其中 ii 是 11 到 nn 之间的整数。对于该查询,出题人将告诉你字符 sis_i;
  • 22 ll rr —— 第二类查询,其中 ll 和 rr 是满足 1≤l≤r≤n1 \le l \le r \le n 的整数。对于该查询,出题人将告诉你子串 sl,sl+1,…,srs_l, s_{l+1}, \dots, s_r 中不同字符的个数。

你最多可进行 2626 次第一类查询,以及最多 60006000 次第二类查询。你的任务是还原字符串 ss。

本题中,对每个测试用例,字符串 ss 在开始前即已固定,并且对所有提交均保持不变。

输入格式

Initially, the jury program sends one integer nn on a separate line — the size of ss (1≤n≤10001 \le n \le 1000).

最初,评测程序会在单独一行发送一个整数 nn —— 字符串 ss 的长度(1≤n≤10001 \le n \le 1000)。

输出格式

To give the answer, print one line ! s with a line break in the end, where ss should be the string picked by the jury. After that, your program should flush the output and terminate gracefully.

要给出答案,请输出一行 ! s,并在末尾换行,其中 ss 应为评测组选定的字符串。之后,你的程序应刷新输出并正常终止。

输入输出样例

  • 输入#1

    5
    4
    u
    2
    g
    e
    s
    1

    输出#1

    ? 2 1 5
    ? 1 2
    ? 2 1 2
    ? 1 1
    ? 1 3
    ? 1 4
    ? 2 4 5
    ! guess

说明/提示

Let's analyze the example of interaction.

The string chosen by the jury is guess, so initially the jury sends one integer 55.

  1. the first query is ? 2 1 5, which means "count the number of different characters among s1,s2,…,s5s_1, s_2, \dots, s_5". The answer to it is 44.
  2. the second query is ? 1 2, which means "tell which character is s2s_2". The answer to it is u.
  3. the third query is ? 2 1 2, which means "count the number of different characters among s1s_1 and s2s_2". The answer to it is 22.
  4. the fourth query is ? 1 1, which means "tell which character is s1s_1". The answer to it is g.
  5. the fifth query is ? 1 3, which means "tell which character is s3s_3". The answer to it is e.
  6. the sixth query is ? 1 4, which means "tell which character is s4s_4". The answer to it is s.
  7. the seventh query is ? 2 4 5, which means "count the number of different characters among s4s_4 and s5s_5". The answer to it is 11, so it's possible to deduce that s4s_4 is the same as s5s_5.

In the end, the answer is submitted as ! guess, and it is deduced correctly.

我们来分析一下交互示例。

评委会选定的字符串是 guess,因此初始时评委会发送一个整数 55。

  1. 第一个查询是 ? 2 1 5,其含义为:“统计 s1,s2,…,s5s_1, s_2, \dots, s_5 中不同字符的个数”。该查询的答案为 44。
  2. 第二个查询是 ? 1 2,其含义为:“告知 s2s_2 是哪个字符”。该查询的答案为 u。
  3. 第三个查询是 ? 2 1 2,其含义为:“统计 s1s_1 和 s2s_2 中不同字符的个数”。该查询的答案为 22。
  4. 第四个查询是 ? 1 1,其含义为:“告知 s1s_1 是哪个字符”。该查询的答案为 g。
  5. 第五个查询是 ? 1 3,其含义为:“告知 s3s_3 是哪个字符”。该查询的答案为 e。
  6. 第六个查询是 ? 1 4,其含义为:“告知 s4s_4 是哪个字符”。该查询的答案为 s。
  7. 第七个查询是 ? 2 4 5,其含义为:“统计 s4s_4 和 s5s_5 中不同字符的个数”。该查询的答案为 11,因此可推断出 s4s_4 与 s5s_5 相同。

最后,提交答案 ! guess,且推断正确。

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

首页