LogoLogo
  • CP Gymnasium
  • Week 3 Math / Number Theory
    • Week 3 Math / Number Theory
      • Problem 1: Tetration
      • Problem 2: Peragrams
      • Problem 3: Veci
      • Problem 4: Architecture
      • Problem 5: Joint Attack
      • Problem 6: How Many Digits?
      • Problem 7: Abstract Painting
  • Week 4 Array / Greedy
    • Week 4 Array / Greedy
      • Problem 1: Vaccine Efficacy
      • Problem 2: Frosh Week
      • Problem 3: Inquiry
      • Problem 4: Bank Queue
      • Problem 5: Log Land
  • Week 6 Sorting / Binary Search
    • Week 6 Sorting / Binary Search
      • Problem 1: Falling Apart
      • Problem 2: Synchronizing Lists
      • Problem 3: Distributing Ballot Boxes
      • Problem 4: Financial Planning
      • Problem 5: Big Boxes
  • Week 7 Dynamic Programming
    • Week 7 Dynamic Programming
      • Problem 1: Ocean's Anti-11
      • Problem 2: Batmanacci
      • Problem 3: Radio Commercials
      • Problem 4: Welcome to Code Jam (Hard)
      • Problem 5: Honeycomb Walk
  • Week 8 Graph Traversals
    • Week 8 Graph Traversals
      • Problem 1: Reachable Roads
      • Problem 2: Money Matters
      • Problem 3: Squawk Virus
      • Problem 4: Beehives
      • Problem 5: Running MoM
      • Problem 6: Amanda Lounges
Powered by GitBook
On this page
  1. Week 3 Math / Number Theory
  2. Week 3 Math / Number Theory

Problem 7: Abstract Painting

https://open.kattis.com/problems/abstractpainting

Color square by square, starting at the top-left square.

To color the top-left square, there are (32)=3\binom{3}{2} = 3(23​)=3ways to choose the two colors for the square. Then, there are (42)=6\binom{4}{2}=6(24​)=6 ways to arrange these colors. So, there are 3⋅6=183 \cdot 6 = 183⋅6=18ways to color the top-left square.

Next, move right and color the rest of the squares in the first row. For these squares, we'll have already colored the square to the left, which means one line is colored already. So, one color is already fixed, and there are then (21)=2\binom{2}{1}=2(12​)=2choices for the second color. Moreover, there are (32)=3\binom{3}{2}=3(23​)=3ways to arrange the remaining three lines of the square. So, there are 2⋅3=62 \cdot 3 = 62⋅3=6ways to color the squares of the first row. Similarly, there are 666ways to color the squares of the first column as well.

For the rest of the squares, we can keep coloring squares with two lines already colored, until we have colored the entire painting. For each square with two lines already colored, there are two cases:

  • Both lines are the same color: there are (21)=2\binom{2}{1}=2(12​)=2ways to choose the second color, and only 111way to color the remaining two lines (both must be the other color). So, there are 2⋅1=22 \cdot 1=22⋅1=2colorings.

  • The two lines are different colors: both colors of the square are defined by these two lines. There are (21)=2\binom{2}{1}=2(12​)=2ways to color the remaining two lines. So there are 2⋅1=22 \cdot 1=22⋅1=2colorings.

Therefore, for these squares, there are always 222colorings.

So, to count the total number of good paintings, start with 18 for the first square. Multiply by 6 for each other square in the first row or first column, and multiply by 2 for every other square. That gives us the expression:

Remember to take mod 1000000007 after each multiplication step to avoid integer overflow! Also, use long longs.

PreviousProblem 6: How Many Digits?NextWeek 4 Array / Greedy

Last updated 4 years ago