CF1672E.notepad.exe

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

This is an interactive problem.

There are nn words in a text editor. The ii -th word has length lil_i ( 1li20001 \leq l_i \leq 2000 ). The array ll is hidden and only known by the grader.

The text editor displays words in lines, splitting each two words in a line with at least one space. Note that a line does not have to end with a space. Let the height of the text editor refer to the number of lines used. For the given width, the text editor will display words in such a way that the height is minimized.

More formally, suppose that the text editor has width ww . Let aa be an array of length k+1k+1 where 1=a1<a2<<ak+1=n+11=a_1 < a_2 < \ldots < a_{k+1}=n+1 . aa is a valid array if for all 1ik1 \leq i \leq k , lai+1+lai+1+1++1+lai+11wl_{a_i}+1+l_{a_i+1}+1+\ldots+1+l_{a_{i+1}-1} \leq w . Then the height of the text editor is the minimum kk over all valid arrays.

Note that if w<max(li)w < \max(l_i) , the text editor cannot display all the words properly and will crash, and the height of the text editor will be 00 instead.

You can ask n+30n+30 queries. In one query, you provide a width ww . Then, the grader will return the height hwh_w of the text editor when its width is ww .

Find the minimum area of the text editor, which is the minimum value of whww \cdot h_w over all ww for which hw0h_w \neq 0 .

The lengths are fixed in advance. In other words, the interactor is not adaptive.

输入格式

The first and only line of input contains a single integer nn ( 1n20001 \leq n \leq 2000 ) — the number of words on the text editor.

It is guaranteed that the hidden lengths lil_i satisfy 1li20001 \leq l_i \leq 2000 .

输出格式

Begin the interaction by reading nn .

To make a query, print "? ww " (without quotes, 1w1091 \leq w \leq 10^9 ). Then you should read our response from standard input, that is, hwh_w .

If your program has made an invalid query or has run out of tries, the interactor will terminate immediately and your program will get a verdict Wrong answer.

To give the final answer, print "! areaarea " (without the quotes). Note that giving this answer is not counted towards the limit of n+30n+30 queries.

After printing a query do not forget to output end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, 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.

Hacks

The first line of input must contain a single integer nn ( 1n20001 \leq n \leq 2000 ) — the number of words in the text editor.

The second line of input must contain exactly nn space-separated integers l1,l2,,lnl_1,l_2,\ldots,l_n ( 1li20001 \leq l_i \leq 2000 ).

输入输出样例

  • 输入#1

    6
    
    0
    
    4
    
    2

    输出#1

    ? 1
    
    ? 9
    
    ? 16
    
    ! 32

说明/提示

In the first test case, the words are {glory,to,ukraine,and,anton,trygub}\{\texttt{glory},\texttt{to},\texttt{ukraine},\texttt{and},\texttt{anton},\texttt{trygub}\} , so l={5,2,7,3,5,6}l=\{5,2,7,3,5,6\} .

If w=1w=1 , then the text editor is not able to display all words properly and will crash. The height of the text editor is h1=0h_1=0 , so the grader will return 00 .

If w=9w=9 , then a possible way that the words will be displayed on the text editor is:

  • \texttt{glory__to}
  • \texttt{ukraine__}
  • \texttt{and_anton}
  • \texttt{__trygub_}

The height of the text editor is h9=4h_{9}=4 , so the grader will return 44 .

If w=16w=16 , then a possible way that the words will be displayed on the text editor is:

  • \texttt{glory_to_ukraine}
  • \texttt{and_anton_trygub}

The height of the text editor is h16=2h_{16}=2 , so the grader will return 22 .

We have somehow figured out that the minimum area of the text editor is 3232 , so we answer it.

首页