EaglePB2's Competitive Programming Writeups
  • Home Page
  • Why Python?
  • Why 10^9 + 7?
  • General Formatting Title
  • 🇲🇾CodeNection
    • 2021
      • Closed Cateogry
        • Attend Talks
        • Distant Relatives
        • Concert
        • Mamak
        • Fair Contest
      • Open Preliminary Round
        • f(Aibohphobia)^-1
        • Did they cheat?
        • Semester Breaks
      • Open Final Round
        • Ways 1
        • Circular Campus
        • A joke
        • 🥰Last year when life was better
        • Thank You Pizza
    • 2023
      • Test Round
        • Codey and Alphabetical Scoring
        • Codey and Binary Guesser
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Hide-and-Seek
        • Codey and Math
        • Codey and Textbooks
        • Codey and Money
        • Codey and Team Selection
        • Codey and Painted Tree
        • Codey and Number Grid
        • Codey and Crimes
      • Final Round
        • Codey and CodeNection 2
        • Codey and Connection
        • Codey and Schedule
        • Codey and School Supplies
        • Codey and Zombies
        • Codey and Sightseeing
        • Codey and Apples
        • Codey and Facto
        • Codey and Zoey
    • 2024
      • Test Round
        • Codey and Sunday
        • Codey and Takoyaki
      • Preliminary Round
        • Codey and CodeNection
        • Codey and Pebbles
        • Codey and Spam
        • Codey and Coins
        • Codey and Rectangles
        • Codey and Manuscript
        • Codey and Recipes
        • Codey and Toy Kingdom
        • Codey and Peaks
      • Final Round
        • Codey and Exit
        • Codey and Gardening
        • Codey and Symbol
        • Codey and Rectangles 2
        • Codey and Jutsu
        • Codey and Toy Kingdom 2
        • Codey and Speeches
  • ABaKoDa
    • 2023
      • Round 1
        • Problem Letters
        • Problem Statistics
        • Rankings Order
        • Rankings Search
      • Round 2
        • Abakoda Letters
        • Borrowed Words
        • Kensorship
        • Duel Languages
  • Meta Coding Competitions
    • 2011
      • Qualification Round
        • Double Squares
        • Peg Game
        • Studious Student
      • Round 1A
        • Diversity Number
        • Turn on the Lights
        • Wine Tasting
      • Round 1B
        • Chess 2
        • Diminishing Circle
        • Slot Machine Hacker
      • Round 1C
        • N-Factorful
        • Polynomial Factoring
        • Risky Slide
      • Round 2
        • Bonus Assignments
        • Scott's New Trick
        • Studious Student II
      • Final Round
        • Alien Game
        • Party Time
        • Safest Place
  • EaglePB2's Special
    • Hong Kong Identity card
    • Cycle Prefix Averages
    • Word Squares
Powered by GitBook
On this page
  • Question
  • Input Format
  • Constraints
  • Output Format
  • Sample Inputs:
  1. EaglePB2's Special

Word Squares

Difficulty: Medium/Hard

Question

Peter wonders that if given a rectangle N * M, with his English dictionary, is possible to fit the words inside the square, which horizontally and vertically are legit English words, while unique. He uses his dictionary to find all the words which has the length of 4 for each side and tries to fit into the square. And finally, he found one of the examples, which as follows:

R

E

S

T

O

V

E

R

S

I

T

E

E

L

S

E

Which in this table, rest, over, site, else, rose, evil, sets and tree are all found in the English dictionary. Now he wonders that how many possibilities does this suffice, given the size of the rectangle and the dictionary source.

Input Format

The first line (which is provided) will read the input.txt, which consists of a list of vocabularies. The second line is the size of the rectangle N and M.

Constraints

3≤len(lines)≤N,M≤103 \le len(lines) \le N, M \le 103≤len(lines)≤N,M≤10
102≤lines≤10510^2 \le lines \le 10^5102≤lines≤105
  • The lines are all in small capitals a-z, no spaces in a line, one word per line.

  • All lines are unique.

Output Format

Output a value which determines the number of ways that words in input.txt can fit into the rectangle.

Sample Inputs:

Input

## Input.txt
rest
over
site
else
away
were
area
year

Output

1

Solution

PreviousCycle Prefix Averages

Last updated 2 months ago