Logo
(追記) (追記ここまで)

28481번 - Fork 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
0.15 초 1024 MB4000.000%

문제

Luca opened a Python shell and typed os.fork(), which spawned a second shell. After that, each time Luca pressed any key, it would randomly go to one of the two shells. Each shell has an input string (shown in the terminal), which is edited by the key presses going to that shell. Additionally, Luca sees the terminal and thus he knows which shell's input string was affected when he presses a key.

His keyboard has $N$ keys with distinct characters on them and Backspace. When a character key press goes to a shell, the character is simply appended to the end of its input string. When a Backspace key press goes to a shell, the last character of its input string is erased. If the shell's input string is empty, nothing happens to it (though Luca still sees the Backspace went there). Each key press has probability $P$ of going to the left shell and probability 1ドル - P$ of going to the right one.

Luca wants to type some fixed string $a_1a_2 \cdots a_N$ consisting of $N$ distinct characters in both shells. He has already managed to type $L$ correct characters to the left shell and $R$ to the right one (i.e. the strings in the two shells are $a_1a_2 \cdots a_L$ and $a_1a_2 \cdots a_R$). For example, consider $P = 0.3,ドル $N = 2$ (the string could be ab), $L = 0$ and $R = 1$. A possible sequence of events is:

Step Key Side Left shell Right shell
0 a
1 b Right ab
2 a Right aba
3 a Left a aba
4 b Right a abab
5 Backspace Right a aba
6 Backspace Left aba
7 Backspace Left aba
8 Backspace Right ab
9 a Left a ab
10 b Right a abb
11 b Left ab abb
12 Backspace Right ab ab

In total, typing ab to both shells took 12ドル$ key presses.

Let us define an incorrect character like so: a character in one of the two shells, which needs to be deleted at some point before typing the full string (and only that) to both shells. Luca has decided that he will never press Backspace, if there is no incorrect character in at least one of the shells. He has also decided that he will never press a key which will always result in an incorrect character. Luca is wondering what his optimal strategy would be under these constraints. In particular, he wants to know what is the minimum expected (average) number of key presses. Help Luca by writing a program fork.cpp which solves this problem.

입력

From the first and only line of the standard input, your program should read $P,ドル $N,ドル $L$ and $R$.

출력

On the first and only line of the standard output, your program should print the computed answer to (preferably) 12ドル$ digits of precision or more. You can use:

std::cout << std::setprecision(12) << ans << std::endl;

제한

  • 0ドル ≤ L, R ≤ N ≤ 2 \times 10^7$
  • 0ドル.1 ≤ P ≤ 0.9$

서브태스크

번호배점제한
115

$N \le 5$

210

$N \le 15$

310

$N \le 35$

415

$N \le 100$

515

$N \le 450$

615

$N \le 1500$

715

$N \le 10^6$

85

$N \le 2 \times 10^7$

To get the points for a given subtask, your solution must successfully pass all tests in it and in all previous subtasks. To pass a test, your solution must print an answer with a relative error at most 10ドル^{-8},ドル i.e.:

$\frac{|yourAns - trueAns|}{trueAns} \le 10^{-8}$ (where $\frac{0}{0} = 0$)

예제 입력 1

0.3 2 0 1

예제 출력 1

16.7142857142857

힌트

출처

Olympiad > International Autumn Tournament in Informatics > 2022 > Group A (Seniors) 5번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /