RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0517

Sleeping in Class

Platinum II 플래티넘 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Bessie the cow was excited to recently return to in-person learning!
Unfortunately, her instructor, Farmer John, is a very boring lecturer, and so
she ends up falling asleep in class often.

Farmer John has noticed that Bessie has not been paying attention in class. He
has asked another student in class, Elsie, to keep track of the number of times
Bessie falls asleep in a given class. There are \(N\) class periods
(\(2\le N\le 10^5\)), and Elsie logs that Bessie fell asleep \(a_i\) times
(\(1\le a_i\le 10^{18}\)) in the \(i\)-th class period. The total number of times
Bessie fell asleep across all class periods is at most \(10^{18}\).

Elsie, feeling very competitive with Bessie, wants to make Farmer John feel like
Bessie is consistently falling asleep the same number of times in every class --
making it appear that the issue is entirely Bessie's fault, with no dependence
on Farmer John's sometimes-boring lectures.

The only ways Elsie may modify the log are by combining two adjacent class
periods or splitting a class period into two. For example, if \(a=[1,2,3,4,5],\)
then if Elsie combines the second and third class periods the log will become
\([1,5,4,5]\). If Elsie then chooses to split the third class period into two, the
log can become any of \([1,5,0,4,5]\), \([1,5,1,3,5]\), \([1,5,2,2,5]\),
\([1,5,3,1,5]\), or \([1,5,4,0,5]\).

Given \(Q\) (\(1\le Q\le 10^5\)) candidates \(q_1,\ldots,q_Q\) for Bessie's least
favorite number (\(1\le q_i\le 10^{18}\)), for each of them help Elsie compute
the minimum number of modifications to the log that she needs to perform so that
all the numbers in the log become the same.

Problem credits: Jesse Choe and Benjamin Qi

제약

SCORING

  • In test cases 2-4, \(N,Q\le 5000\)
  • In test cases 5-7, all \(a_i\) are at most \(10^9\).
  • Test cases 8-26 satisfy no additional constraints.

Problem credits: Jesse Choe and Benjamin Qi

입력 형식

The first line of each test case contains \(N\), and the second contains
\(a_1,a_2,\ldots,a_N\). The third contains \(Q\), followed by \(Q\) lines each
containing an integer \(q_i\), a candidate for Bessie's least favorite number.

출력 형식

For each \(q_i\), compute the minimum number of modifications required for Elsie
to convert every entry of the log into \(q_i\), or \(-1\) if it is impossible.

예제 1
입력
6
1 2 3 1 1 4
7
1
2
3
4
5
6
12
출력
6
6
4
5
-1
4
5
설명

Elsie needs at least four modifications to convert the log into all 3s.

   1 2 3 1 1 4
-> 3 3 1 1 4
-> 3 3 1 5
-> 3 3 6
-> 3 3 3 3

It is impossible for Elsie to convert the log into all 5s, which is why the
correct output for that candidate is \(-1\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2021-2022 > February > Platinum

태그

평가 및 의견

Sleeping in Class

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Sleeping in Class

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8