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

Bessie's Function

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

의견: 0

설명

Bessie has a special function \(f(x)\) that takes as input an integer in \([1, N]\)
and returns an integer in \([1, N]\) (\(1 \le N \le 2 \cdot 10^5\)). Her function
\(f(x)\) is defined by \(N\) integers \(a_1 \ldots a_N\) where \(f(x) = a_x\)
(\(1 \le a_i \le N\)).

Bessie wants this function to be idempotent. In other words, it should satisfy
\(f(f(x)) = f(x)\) for all integers \(x \in [1, N]\).

For a cost of \(c_i\), Bessie can change the value of \(a_i\) to any integer in
\([1, N]\) (\(1 \le c_i \le 10^9\)). Determine the minimum total cost Bessie needs
to make \(f(x)\) idempotent.

Problem credits: Avnith Vijayram

제약

SCORING

Subtasks:

  • Input 3: \(N\le 20\)
  • Inputs 4-9: \(a_i\ge i\)
  • Inputs 10-15: All \(a_i\) are distinct.
  • Inputs 16-21: No additional constraints.

Additionally, in each of the last three subtasks, the first half of tests will
satisfy \(c_i=1\) for all \(i\).

Problem credits: Avnith Vijayram

입력 형식

The first line contains \(N\).

The second line contains \(N\) space-separated integers \(a_1,a_2,\dots,a_N\).

The third line contains \(N\) space-separated integers \(c_1,c_2,\dots,c_N\).

출력 형식

Output the minimum total cost Bessie needs to make \(f(x)\) idempotent.

예제 1
입력
5
2 4 4 5 3
1 1 1 1 1
출력
3
설명

We can change \(a_1 = 4\), \(a_4 = 4\), \(a_5 = 4\). Since all \(c_i\) equal one, the
total cost is equal to \(3\), the number of changes. It can be shown that there is
no solution with only \(2\) or fewer changes.

예제 2
입력
8
1 2 5 5 3 3 4 4
9 9 2 5 9 9 9 9
출력
7
설명

We change \(a_3 = 3\) and \(a_4 = 4\). The total cost is \(2+5=7\).

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > February > Gold

태그

평가 및 의견

Bessie's Function

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

Log in to rate problems.

개별 의견

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

풀이 제출

Bessie's Function

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