No.11 Card Match
タグ : / 解いたユーザー数 504
作問者 :
Problem Statement
Jen is playing a card game with \(W \times H\) cards.
Jen wants to know the number of cards outside her hand that match any of the cards in her hand (whose faces she can see).
This deck has \(W\) kinds of suits and numbers from \(1\) to \(H\), and no combination is duplicated.
Here, a card matches if either its suit or its number is the same.
There are now \(N\) cards in her hand. Find the number of matching cards among "the cards other than those in her hand".
\(W \times H\) may be \(2^{32}\) or greater.
Input
\(W\) \(H\) \(N\) \(S_1\ K_1\) \(S_2\ K_2\) \(\dots\) \(S_i\ K_i\) \(\dots\) \(S_N\ K_N\)
The \(1\)st line contains an integer \(W\ (1 \leq W \leq 1,000,000) \), the number of kinds of suits in the deck.
The \(2\)nd line contains an integer \(H\ (1 \leq H \leq 1,000,000) \), the maximum number in the deck.
The \(3\)rd line contains an integer \(N\ (1 \leq N \leq min(W \times H, 100)) \), the number of cards in her hand.
Each of the following \(N\) lines contains \(S_i\ (1 \leq S_i \leq W) \) and \(K_i\ (1 \leq K_i \leq H) \), separated by a space, representing the suit and number of a card in her hand.
It is guaranteed that when $i \neq j$, the pairs of values $(S_i, K_i)$ and $(S_j, K_j)$ are different.
Output
Output the number of matching cards among "the cards other than those in her hand".
Sample
Sample 1
Input
2 5 1 1 1
Output
5
The deck consists of the combinations of \(2\) kinds of suits and \(5\) numbers.
In this case,
"the \(4\) cards of suit \(1\) other than \(1\)" and "the \(1\) of suit \(2\)" match.
Sample 2
Input
4 13 3 1 1 2 1 2 5
Output
27
This is the same as a real-world deck of playing cards.
In this case, the matching cards are
"the cards of suit \(1\) other than \(1\)", "the cards of suit \(2\) other than \(1,5\)", and "the \(1\) and \(5\) of suit \(3\) and suit \(4\)".
Sample 3
Input
4 13 4 1 5 2 6 3 7 4 8
Output
48
Sample 4
Input
3 2 2 1 1 2 1
Output
3
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。