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

Lights Off

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

의견: 0

설명

Note: The time limit for this problem is 4s, twice the default.

Bessie wants to go to sleep, but the farm's lights are keeping her awake. How
can she turn them off?

Bessie has two bit strings of length \(N\) (\(2\le N\le 20\)), representing a
sequence of lights and a sequence of switches, respectively. Each light is
either on (1) or off (0). Each switch is either active (1) or inactive (0).

A move consists of the following sequence of operations:

  1. Toggle exactly one switch (set it to active if it is inactive, or vice versa).
  2. For each active switch, toggle the state of the corresponding light (turn it off if it is on, or vice versa).
  3. Cyclically rotate the switches to the right by one. Specifically, if the bit string corresponding to the switches is initially \(s_0s_1\dots s_{N-1}\) then it becomes \(s_{N-1}s_0s_1\dots s_{N-2}\).

For \(T\) (\(1\le T\le 2\cdot 10^5\)) instances of the problem above, count the
minimum number of moves required to turn all the lights off.

Problem credits: William Yue, Eric Yang, and Benjamin Qi

제약

SCORING

  • Inputs 3-5: \(N \le 8\)
  • Inputs 6-13: \(N\le 18\)
  • Inputs 14-20: No additional constraints.

Problem credits: William Yue, Eric Yang, and Benjamin Qi

입력 형식

First line contains \(T\) and \(N\).

Next \(T\) lines each contain a pair of length-\(N\) bit strings.

출력 형식

For each pair, the minimum number of moves required to turn all the lights off.

예제 1
입력
4 3
000 101
101 100
110 000
111 000
출력
0
1
3
2
설명
  • First test case: the lights are already all off.
  • Second test case: We flip the third switch on the first move.
  • Third test case: we flip the first switch on the first move, the second switch on the second move, and the second switch again on the third move.
  • Fourth test case: we flip the first switch on the first move and the third switch on the second move.

It can be shown that in each case this is the minimal number of moves necessary.

예제 2
입력
1 10
1100010000 1000011000
출력
2
설명

It can be shown that \(2\) moves are required to turn all lights off.

  • We flip the seventh switch on the first move and then again on the second move.
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2022-2023 > January > Gold

태그

평가 및 의견

Lights Off

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

Log in to rate problems.

개별 의견

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

풀이 제출

Lights Off

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