Logo
(追記) (追記ここまで)

25095번 - Weightlifting 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
20 초 (추가 시간 없음) 1024 MB77565074.627%

문제

You are following a prescribed training for weightlifting. The training consists of a series of exercises that you must do in order. Each exercise requires a specific set of weights to be placed on a machine.

There are $W$ types of different weights. For example, an exercise may require 3ドル$ weights of type A and 1ドル$ weight of type B, while the next requires 2ドル$ weights each of types A, C, and D.

The weights are placed on the machine as a stack. Formally, with a single operation, you can either add a new weight of any type to the top of the stack, or remove the weight that is currently at the top of the stack.

You can load the weights for each exercise onto the machine's stack in any order. So, if you place the weight of type B at the bottom in the first exercise of the example above, you will have to take all the weights off before putting on the weights for the second exercise. On the other hand, if you place the weight of type B third from the bottom, you can leave two of the weights of type A on the bottom of the stack to be part of the next exercise's set, saving you some time.

Given the amount of weights of each type needed for each exercise, find the minimum number of operations needed to do them all. You must complete the exercises in the order given. The machine stack starts out empty, and you must leave it empty after you finish with all your exercises.

입력

The first line of the input gives the number of test cases, $T$. $T$ test cases follow. Each test case starts with a line containing 2ドル$ integers $E$ and $W$: the number of exercises and the number of types of weights. Weight types are numbered between 1ドル$ and $W$. Then, $E$ lines follow. The $i$-th of these lines contains $W$ integers $X_{i,1},X_{i,2},\dots,X_{i,W}$ representing that the $i$-th exercise requires exactly $X_{i,j}$ weights of type $j$.

출력

For each test case, output one line containing Case #x: y, where $x$ is the test case number (starting from 1) and $y$ is the minimum number of machine stack operations needed to run through all your exercises.

제한

  • 1ドル≤T≤100$.
  • 1ドル≤X_{i,1}+X_{i,2}+\cdots+X_{i,W},ドル for all $i$. (Each exercise requires at least one weight.)

Test Set 1 (13점)

  • 1ドル≤E≤10$.
  • 1ドル≤W≤3$.
  • 0ドル≤X_{i,j}≤3,ドル for all $i,j$.

Test Set 2 (31점)

  • 1ドル≤E≤100$.
  • 1ドル≤W≤100$.
  • 0ドル≤X_{i,j}≤100,ドル for all $i,j$.

예제 입력 1

3
3 1
1
2
1
2 3
1 2 1
2 1 2
3 3
3 1 1
3 3 3
2 3 3

예제 출력 1

Case #1: 4
Case #2: 12
Case #3: 20

힌트

In Sample Case #1, there is only one type of weight. The first exercise needs 1ドル$ weight, the second needs 2ドル$ weights, and the third needs 1ドル$ weight. You can complete the exercise in 4ドル$ operations as follows:

  1. Add a weight onto the stack. You do the first exercise.
  2. Add a weight onto the stack. You do the second exercise.
  3. Remove a weight from the top of the stack. You do the third exercise.
  4. Remove a weight from the top of the stack. Now the stack becomes empty.

In Sample Case #2, one way to complete the exercises in 12ドル$ operations is as follows:

  1. Add a weight of type 2ドル$.
  2. Add a weight of type 3ドル$.
  3. Add a weight of type 1ドル$.
  4. Add a weight of type 2ドル$. Now the stack contains weights of types 2ドル,ドル 3ドル,ドル 1ドル,ドル 2ドル$ from bottom to top. You do the first exercise.
  5. Remove a weight of type 2ドル$ from the top of the stack.
  6. Add a weight of type 3ドル$.
  7. Add a weight of type 1ドル$. Now the stack contains weights of types 2ドル,ドル 3ドル,ドル 1ドル,ドル 3ドル,ドル 1ドル$ from bottom to top. You do the second exercise.
  8. Remove a weight of type 1ドル$ from the top of the stack.
  9. Remove a weight of type 3ドル$ from the top of the stack.
  10. Remove a weight of type 1ドル$ from the top of the stack.
  11. Remove a weight of type 3ドル$ from the top of the stack.
  12. Remove a weight of type 2ドル$ from the top of the stack. Now the stack becomes empty.

출처

Contest > Google > Code Jam > Google Code Jam 2022 > Round 1A C번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /