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

Good Cyclic Shifts

Gold II 골드 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

For a permutation \(p_1,p_2,\dots,p_N\) of \(1\dots N\) (\(1\le N\le 2\cdot 10^5\)),
let \(f(p)=\sum_{i=1}^N \frac{|p_i-i|}{2}\). A permutation is
good
if it can be turned into the identity permutation using at most \(f(p)\) swaps of
adjacent elements.

Given a permutation, find which cyclic shifts of it are good.

Problem credits: Akshaj Arora

제약

SCORING

  • Input 2: \(N\le 10\)
  • Inputs 3-5: \(T\le 10, N\le 2000\)
  • Inputs 6-11: No additional constraints.

Problem credits: Akshaj Arora

입력 형식

The input consists of \(T\) (\(1\le T\le 10^5\)) independent tests. Each test is
specified as follows:

The first line contains \(N\).

The second line contains \(p_1,p_2,\dots,p_N\) (\(1\le p_i\le N\)), which is
guaranteed to be a permutation of \(1\dots N\).

It is guaranteed that the sum of \(N\) over all tests does not exceed \(10^6\).

출력 형식

For each test, output two lines:

On the first line, output the number of good cyclic shifts \(k\).

Then output a line with \(k\) space-separated integers \(s\) (\(0\le s) in
increasing order, meaning that \(p\) is good when cyclically shifted to the right
\(s\) times.

예제 1
입력
3
5
5 4 3 2 1
4
1 2 4 3
5
1 2 3 4 5
출력
0

2
0 1
5
0 1 2 3 4
설명

Consider the second test case, where \(p = [1, 2, 4, 3]\).

  • \(f(p) = (|1 - 1| + |2 - 2| + |4 - 3| + |3 - 4|) / 2 = 1\). Since \(p\) can be turned into the identity permutation in one move by swapping \(p_3\) and \(p_4\), \(p\) is good.
  • Cyclically shifting \(p\) to the right \(1\) time, we get \(q = [3, 1, 2, 4]\). \(f(q) = (|3 - 1| + |1 - 2| + |2 - 3| + |4 - 4|) / 2 = 2\). Since \(q\) can be turned into the identity permutation in two moves by swapping \(q_1\) two steps forward, \(q\) is good.

It can be seen that the other two cyclic shifts are not good.

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > Third Contest > Gold

태그

평가 및 의견

Good Cyclic Shifts

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

Log in to rate problems.

개별 의견

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

풀이 제출

Good Cyclic Shifts

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