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

Poklon

Unrated 레이팅 미적용
난이도
1s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

1 \(s / 256\) \(MB / 120\) points

The main (potentially tragic) hero of this task is Kile, otherwise known as the joker from the

bench of the semiliterate team El Locos

, and who is celebrating his birthday today.

His best friend Ivan has decided to gift him a special pharmaceutical scale. The specialty of

this scale is that it is recursive, i.e., at the end of each beam, there is either a weight, a new

scale, or nothing. Of course, the scale leans to the left if the total mass on its left beam is

larger than the total mass on its right beam. Analogously, if the mass is larger on the right

beam, then the scale leans to the right. Otherwise, we say that the scale is balanced.

Kile really likes the gift, and, as a true computer scientist, he immediately tries to balance it

using new weights for which total mass is the lowest possible . New weights should be

positive real numbers. We say that a recursive scale is balanced if it is balanced and all its

subscales are balanced.

After having successfully balanced the scale, Kile decided to tattoo on his chest the total

mass of the weights placed on the scale, in binary notation, without leading zeros. What

number is tattooed on Kile’s chest?

제약
입력 형식

The first line of input contains the positive integer
that represents the total

(1
\(N\)
)
\(N\)

\(10^{6}\)

number of scales Kile’s recursive scale consists of (including itself).

The \(i\)^{th} of the following \(N\) lines contains two whole numbers that respectively describe the left

and the right beam of the scale with index \(i\)

. A positive number in the scale description

denotes the index of the scale located on that beam, whereas a n\(on-po\)sitive number

denotes that there is a weight on that beam, with its mass corresponding to the absolute

value of the number. Root scale which contains all other scales has index 1.

All numbers from the input are in absolute value less than or equal to
.
\(10^{9}\)

출력 형식

The first and only line of output must contain the total mass of the weights located on Kile’s

scale. This number needs to be in binary notation, without leading zeros.

1 \(s / 256\) \(MB / 120\) points

예제 1
입력
2
2 -10
-4 -3

4
2 3
-9 4
-2 -13
-1 -7
출력
output
10100

111000
설명

Clarification of the first test case:
The example corresponds to the image from the task. Kile will add another weight of mass 1 to the

weight of mass 4, and will add another weight of mass 2 to the weight of mass 3. After this, the mass of

both beams of the scale with index 2 is equal to 5, so it is balanced, and the mass of both beams of the

scale with index 1 is 10, so it is balanced as well. The entire scale is now balanced, and the total mass is

5+5+10=20, i.e., 10100 in binary notation.

문제 정보

생성자가 기록되지 않았습니다.

출처 COCI 2016/2017 Contest 7

평가 및 의견

Poklon

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

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

풀이 제출

Poklon

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