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

19825번 - Minimal Product 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB63231745.946%

문제

You are given an array of integers $a_1,\dots,a_n$. Find two indices $i$ and $j$ such that $i<j,ドル $a_i<a_j,ドル and the product $a_i \cdot a_j$ is as small as possible.

입력

The input consists of several tests. The first line contains a single integer $t$ --- the number of tests (1ドル \leq t \leq 10^4$). Each of the following $t$ lines describes one test.

Each test is generated using the following algorithm. The test is described by integers $n,ドル $l,ドル $r,ドル $x,ドル $y,ドル $z,ドル $b_1,ドル $b_2$ (2ドル \leq n \leq 10^7,ドル $-2\cdot10^9 \leq l \leq r \leq 2\cdot10^9,ドル 0ドル \leq x,y,z,b_1,b_2 < 2^{32}$), where $n$ is the length of the array.

First, the sequence $b_i$ of length $n$ is generated. Elements $b_1$ and $b_2$ are given. For $i>2$ let $b_i=(b_{i-2}x+b_{i-1}y+z) \bmod 2^{32}$. For each $i$ between 1ドル$ and $n,ドル $a_i=(b_i \bmod (r - l + 1)) + l$ (thus, $-2\cdot10^9 \leq a_i \leq 2\cdot10^9$).

It is recommended to use 64-bit integers to generate the sequence to avoid integer overflow.

The sum of $n$ in all tests does not exceed 2ドル \cdot 10^7$.

출력

For each test, print the smallest possible product $a_i \cdot a_j$ in a separate line. If there are no such $i$ and $j$ that $i<j$ and $a_i<a_j,ドル print "IMPOSSIBLE".

제한

예제 입력 1

2
4 -5 5 11 13 17 0 3
5 0 100 0 1 0 42 42

예제 출력 1

-15
IMPOSSIBLE

힌트

Let us consider the generation of the array in the first test.

First, the sequence $b$ is generated.

  • $b_1 = 0$
  • $b_2 = 3$
  • $b_3 = (11\cdot 0 + 13\cdot 3 + 17)\bmod 2^{32}=56$
  • $b_4 = (11\cdot 3 + 13\cdot 56 + 17)\bmod 2^{32}=778$

Then it is used to generate $a$.

  • $a_1 = (0\bmod (5-(-5) + 1)) + (-5)=(0 \bmod 11) - 5 = -5$
  • $a_2 = (3 \bmod 11) - 5 = -2$
  • $a_3 = (56 \bmod 11) - 5 = -4$
  • $a_4 = (778 \bmod 11) - 5 = 3$

Thus, $a = [-5,-2,-4,3]$. The answer is $-5 \cdot 3=-15$.

In the second test the array is $[42,42,42,42,42]$.

출처

Olympiad > Russian Olympiad in Informatics > Russia Team High School Programming Contest > Russia Team High School Programming Contest 2018 I번

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

출처

대학교 대회

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

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