Codeforces Round 1286C1 #612 (Div. 1) C1. Madhouse (Easy version) 解题思路 - 排列组合&字符串

Codeforces Round #612 (Div. 1) C1. Madhouse (Easy version)

This problem is different with hard version only by constraints on total answers length

It is an interactive problem

Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string 𝑠 of length 𝑛, consisting only of lowercase English letters. The player can ask two types of queries:

  • ? l r – ask to list all substrings of 𝑠[𝑙…𝑟]
    . Substrings will be returned in random order, and in every substring, all characters will be randomly shuffled.
  • ! s – guess the string picked by the orderlies. This query can be asked exactly once, after that the game will finish. If the string is guessed correctly, the player wins, otherwise he loses.
    The player can ask no more than 3 queries of the first type.

To make it easier for the orderlies, there is an additional limitation: the total number of returned substrings in all queries of the first type must not exceed (𝑛+1)*(n+1).

Venya asked you to write a program, which will guess the string by interacting with the orderlies’ program and acting by the game’s rules.

Your program should immediately terminate after guessing the string using a query of the second type. In case your program guessed the string incorrectly, or it violated the game rules, it will receive verdict Wrong answer.

Note that in every test case the string is fixed beforehand and will not change during the game, which means that the interactor is not adaptive.

Input
First line contains number 𝑛 (1≤𝑛≤100) — the length of the picked string.

Interaction
You start the interaction by reading the number 𝑛.
To ask a query about a substring from 𝑙 to 𝑟 inclusively (1≤𝑙≤𝑟≤𝑛), you should output
? l r
on a separate line. After this, all substrings of 𝑠[𝑙…𝑟] will be returned in random order, each substring exactly once. In every returned substring all characters will be randomly shuffled.

In the case, if you ask an incorrect query, ask more than 3 queries of the first type or there will be more than (𝑛+1)*(n+1)
substrings returned in total, you will receive verdict Wrong answer.

To guess the string 𝑠, you should output
! s
on a separate line.

After printing each query, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To flush the output, you can use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see documentation for other languages.

If you received - (dash) as an answer to any query, you need to terminate your program with exit code 0 (for example, by calling exit(0)). This means that there was an error in the interaction protocol. If you don’t terminate with exit code 0, you can receive any unsuccessful verdict.

Hack format

To hack a solution, use the following format:

The first line should contain one integer 𝑛 (

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值