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

17556번 - Crosswords 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB144466.667%

문제

In order to attract more tourists in Paris, Anne wants to organize a huge sound and light show at night on the facades of the Louvre palace. The facades are showing windows on several levels, and the windows are also vertically aligned. So Anne has the idea of displaying giant letters through the windows, one per window, so that it forms words both horizontally and vertically.

On a given facade, windows are organized on a rectangular grid with N rows and M columns. Anne has gathered a list of A of N-letter words and a list of size B of M-letter words. She is wondering how many ways there are to display simultaneously N words of length M horizontally and M words of length N vertically on that grid.

입력

The input consists of the following:

  • The first line contains two integers N and A separated with a single space.
  • The second line contains two integers M and B separated with a single space.
  • The next A lines contains N-letter words, one per line.
  • The next B lines contains M-letter words, one per line.

출력

The output should consist of a single line, whose content is an integer, the total number of distinct word grids.

제한

The input satisfies 2 ≤ N, M ≤ 4 and 1 ≤ A × B ≤ 1 008 016.

Words are taken from the English dictionary. Each of the two lists contains no repetition. Words consist of lowercase letters between ‘a’ (ASCII code 97) and ‘z’ (ASCII code 122).

Words from the first list will be displayed vertically, from top to bottom. Words from the second list will be displayed horizontally, from left to right. The same word can be used several times to build a grid, i.e., in several columns (resp., rows) if it belongs to the first (resp., second) list of words.

When N = M, it is not allowed to use words from the first list horizontally (unless they appear in the second list as well), or words from the second list vertically (unless they appear in the first list as well).

예제 입력 1

3 4
4 5
war
are
yes
sat
says
area
test
ways
rest

예제 출력 1

2

예제 입력 2

3 7
3 7
ran
age
now
its
the
set
ago
ran
age
now
its
the
set
ago

예제 출력 2

2

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > SWERC 2018 C번

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

출처

대학교 대회

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

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