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

23682번 - $J$ The Attacker Has 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 512 MB52240.000%

문제

This problem is about the Braindead card game which is invented on 21 February 2019 and is loosely based on some other unspecified card game. It is fairly easy to guess though.

There are cards of $n$ suits and $m$ ranks. Some suits are trumps. Note that there may be multiple trumps or none at all. Unlike most actual card games multiple cards may share both rank and suit.

There are two players. Each of them has some non-empty set of cards. This set of cards is called the hand. Both players know each other's hands. The cards in the hand of some player are called his cards.

A card of suit $s_1$ with rank $r_1$ beats a card of suit $s_2$ and rank $r_2$ if one of the following conditions hold:

  1. $s_1 = s_2$ and $r_1 > r_2$
  2. $s_1$ is a trump and $s_2$ is not a trump.

One of the player is the attacker and the other is the defender. The following steps happen

  1. The attacker starts the round by playing one of his cards. This is called the starting attack.
  2. The defender plays one of his cards, which beats the last card the attacker played. If the defender has no such card he loses the game.
  3. The attacker plays one of his cards, such that its rank is equal to the rank of some card played before by either player. If the attacker has no such card he loses the game.
  4. Go to Step 2.

A player can not play the same card twice.

How many starting attacks are there, such that the attacker wins the game from there assuming players play optimally afterwards (after the starting attack)? Starting attacks which play different cards with the same rank and suit are considered different starting attacks.

입력

The first line contains two integers $n$ and $m$ (1ドル \leq n,m \leq 18$), the number of suits and ranks, respectively.

The second line contains $n$ integers $t_i$ (0ドル \leq t_i \leq 1$). $t_i$ is equal to 1ドル$ if the $i$-th suit is a trump and to 0ドル$ if it is a regular suit (not a trump).

Next $n$ lines describe the hand of the attacker. $i$-th of them contains $m$ integers $a_{i,j}$ (0ドル \leq a_{i, j} \leq 10^{12}$). $a_{i,j}$ is equal to the number of cards of suit $i$ with rank $j$ the attacker has.

Next $n$ lines describe the hand of the defender in the same format.

It is guaranteed that both players hands are non-empty.

출력

Output a single integer --- the number of winning first attacks.

제한

예제 입력 1

3 2
0 0 1
1 1
1 0
1 0
0 1
0 1
1 1

예제 출력 1

0

예제 입력 2

3 1
0 1 0
1
0
1
0
1
0

예제 출력 2

2

예제 입력 3

2 4
1 1
5 5 5 0
0 0 0 0
5 5 5 0
0 0 0 10

예제 출력 3

15

예제 입력 4

4 13
1 0 1 0
3 2 0 2 0 3 0 0 3 5 2 1 5
3 3 2 2 2 1 0 4 5 1 5 3 3
1 4 4 2 0 3 2 5 2 5 0 5 3
3 5 4 2 3 3 4 2 2 4 3 2 3
4 3 4 9 0 4 0 1 4 0 1 2 5
1 8 8 6 5 1 1 7 2 4 1 3 9
3 7 3 1 8 9 2 0 0 1 9 6 6
4 6 6 7 9 5 3 2 9 5 0 7 8

예제 출력 4

97

예제 입력 5

1 2
0
4294967296 0
0 2147483647

예제 출력 5

4294967296

힌트

출처

Contest > Open Cup > 2018/2019 Season > Stage 13: Grand Prix of Bytedance J번

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

출처

대학교 대회

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

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