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 4: Architecture

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

Let xxx be the maximum of x1,...,xRx_1,...,x_Rx1​,...,xR​(the second line of input), and let yyybe the maximum of y1,...,yCy_1,...,y_Cy1​,...,yC​ (the third line of input).

If x=yx = yx=y, we can always assign building heights. For example, consider the input:

4 4
3 2 4 2
1 4 1 1

Here, x=y=4x=y=4x=y=4. Then, we can always use the row and column of xxx and yyy for the skylines, and fill the rest of the table with 0s:

(0300020014110200)\begin{pmatrix} 0 & 3 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ 1 & 4 & 1 & 1 \\ 0 & 2 & 0 & 0 \end{pmatrix}​0010​3242​0010​0010​​

If x>yx > yx>y, there must still be an entry in the table with value xxx, so that the eastern skyline can have xxx in one row. Then, the column with that entry will have to have a skyline of height ≥x\geq x≥x too, but as the maximum northern skyline height yyy is less thanxxx, this is impossible. Similarly, x<yx<yx<yis also impossible.

So, output possible if x=yx=yx=y, and output impossible otherwise.

C++ has a function max_element() which finds the max number in a vector. Example usage:

vector<int> v = {3, 1, 4, 7, 2};
int m = *max_element(v.begin(), v.end()); // m will be 7
PreviousProblem 3: VeciNextProblem 5: Joint Attack

Last updated 4 years ago