Generate Optimal Key

시간 제한2초메모리 제한2048 MB

요약
길이 L의 이진 문자열 n개와 금지된 이진 문자열 m개가 주어질 때, n개 각각과 다른 위치 수의 합이 최소가 되는 허용된 문자열을 고른다.
난이도

쉬움10점 중 3점

유형
그리디, 구현, 완전 탐색
정답자
아직 제출이 없습니다

문제

A pattern is defined as a binary string of length LL. Given nn patterns, we want to find a key which is also a binary string of length LL.

For a given pattern and a given key, the error value is defined as the number of positions where the key differs from the pattern. For example, if the pattern is 101, and the key is 000, then the first and third positions are different, so the error value is 22.

We want to find a key such that the sum of the error values for this key and the given nn patterns is minimized. Additionally, there are mm distinct forbidden keys, and the key we find cannot be one of the forbidden keys.

입력

The first line of input contains three integers, nn, mm, and LL (1≤n≤10001 \le n \le 1000; 1≤m≤min⁡(1000,2L−1)1 \le m \le \min(1000, 2^L - 1); 1≤L≤10001 \le L \le 1000).

Each of the following nn lines represents a pattern and contains a binary string of length LL.

Each of the following mm lines represents a forbidden key and contains a binary string of length LL. All forbidden keys are distinct.

출력

Output a single integer: the minimum sum of error values for a non-forbidden key and the nn given patterns if we select the key optimally.

예제2

  1. 예제 1

    입력
    4 1 4
    0000
    1000
    1100
    1010
    1000
    
    예상 출력
    5
    
  2. 예제 2

    입력
    2 4 4
    0000
    0000
    0000
    1000
    0100
    0010
    
    예상 출력
    2