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

Arranging Cows

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

의견: 0

설명

You are given a length-\(N\) bitstring \(s_{1\dots N}\) (\(2\le N\le 10^9\)). In one
operation, you can reverse a range \(s_{l\dots r}\) if the following conditions
are true:

  1. The size of the range is even.
  2. The first half of the range consists of one character (either \(0\) or \(1\)), and the second half contains the opposite character
  3. Either \(l = 1\) or \(s_{l-1} \neq s_l\)
  4. Either \(r = N\) or \(s_{r+1} \neq s_r\)

Find the minimum number of operations to move all of the \(1\)s to the front, or
report that it is impossible. If it is possible to do so, also output the number
of sequences of operations achieving this minimum, modulo \(10^9+7\).

Problem credits: Sujay Konda

제약

SCORING

  • Input 3: \(N \leq 10\), all tests are distinct
  • Input 4: \(R\le 10\)
  • Inputs 5-8: \(R\le 100\), the sum of \(R^2\) over all tests does not exceed \(10^5\), the minimum number of operations is guaranteed to equal \(R/2-1\).
  • Inputs 9-12: \(R\le 100\), the sum of \(R^2\) over all tests does not exceed \(10^5\).
  • Inputs 13-16: No additional constraints.

Problem credits: Sujay Konda

입력 형식

The first line contains \(T\) (\(1 \leq T \leq 2026\)), the number of independent
tests. Each test is specified in the following format:

The bitstring is given in a compressed format. The first line contains \(R\), the
number of runs in the string (\(2\le R\le 800\)), and the first character of the
string (either 0 or 1).

The next line contains \(R\) space-separated integers \(l_1,l_2,l_3,\ldots l_R\)
(\(0), the lengths of maximal consecutive blocks of equal characters in
\(s\). It's guaranteed that \(N=\sum_{i=1}^Rl_i\le 10^9\).

Additionally, it is guaranteed that the sum of \(R^2\) over all tests does not
exceed \(1.5\cdot 10^6\).

출력 형식

For each test case, print the minimum number of operations to move all of the
\(1\)s to the front or \(-1\) if it is impossible, as well as the number of
sequences of operations achieving this minimum modulo \(10^9+7\).

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

Here is the sequence of two operations for the fifth testcase:
\(010110 \to 100110 \to 111000.\)

예제 2
입력
5
2 1
1 1
4 1
1 1 1 1
6 1
1 1 1 1 1 1
8 1
1 1 1 1 1 1 1 1
10 1
1 1 1 1 1 1 1 1 1 1
출력
0 1
1 1
2 1
3 3
4 9
설명

In all of these test cases, the minimum number of operations equals \(R/2-1\).

Here are all three possible sequences of three operations for the fourth test
case:

(1)
   10101010
-> 11001010
-> 11001100
-> 11110000

(2)
   10101010
-> 10110010
-> 10001110
-> 11110000

(3)
   10101010
-> 10101100
-> 11001100
-> 11110000
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2025-2026 > US Open

태그

평가 및 의견

Arranging Cows

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

Log in to rate problems.

개별 의견

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

풀이 제출

Arranging Cows

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