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

Farmer John Loves Rotations

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

의견: 0

설명

Farmer John has an array \(A\) containing \(N\) integers
(\(1 \leq N \leq 5 \cdot 10^5, 1 \leq A_i \leq N\)). He picks his favorite index
\(j\) and take out a sheet of paper with only \(A_j\) written on it. He can then
perform the following operation some number of times:

  • Cyclically shift all elements in \(A\) one spot to the left or one spot to the right. Then, write down \(A_j\) on a piece of paper.

Let \(S\) denote the set of distinct integers that occur in \(A\). Farmer John
wonders what the minimum number of operations he must perform is so that the
paper contains all integers that appear in \(S\).

Since it is unclear what FJ's favorite index is, output the answer for all
possible favorite indices \(1 \leq j \leq N\). Note for each index, \(A\) is reset
to its original form before performing any operations.

Problem credits: Chongtian Ma

제약

SCORING

  • Inputs 3-5: \(N\le 500\)
  • Inputs 6-8: \(N\le 10^4\)
  • Inputs 9-17: No additional constraints.

Problem credits: Chongtian Ma

입력 형식

The first line contains \(N\).

The following line contains \(A_1, A_2, \ldots, A_N\).

출력 형식

Output \(N\) space-separated integers, where the \(i\)'th integer is the answer for
his favorite index \(j = i\).

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

The distinct numbers are \(S = \{ 1, 2, 3, 4 \}\). Suppose Farmer John’s
favorite index is \(j=1\). He starts off with \(A_1=1\) written on a piece of paper.
We can track the array \(A\) after each cyclic shift Farmer John makes.

  1. Cyclic shift right: FJ writes down \(A_1 = 4\).
 4 1 2 3 1 3
  1. Cyclic shift left: FJ writes down \(A_1 = 1\) again.
 1 2 3 1 3 4
  1. Cyclic shift left: FJ writes down \(A_1 = 2\).
 2 3 1 3 4 1
  1. Cyclic shift left: FJ writes down \(A_1 = 3\).
 3 1 3 4 1 2

At this point, Farmer John has written down every number in \(S\) using 4
operations.

예제 2
입력
12
1 1 2 1 1 3 1 1 4 1 1 1
출력
8 7 6 7 8 9 8 7 6 7 8 9
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > Second Contest > Silver

태그

평가 및 의견

Farmer John Loves Rotations

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

Log in to rate problems.

개별 의견

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

풀이 제출

Farmer John Loves Rotations

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