| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 (추가 시간 없음) | 1024 MB (추가 메모리 없음) | 113 | 42 | 35 | 44.872% |
KAIST is running out of budget — they need some money! They thought the dormitories were way too luxurious compared to the other buildings of KAIST; they planned to sell all the dormitory buildings and build a new completely non-aesthetic one.
The new dormitory will be of a grid-shape — it can’t be more boring than this — of size $N\times M,ドル each cell being the room for the students. We are going to add some windows, because we want students to get some sunlight during the daytime!
We plan to have exactly $w_{i,j}$ windows for the room $(i,j)$. A window can be built on the side of an edge of a grid, and at most one window can be built on each side of an edge. A window is one-sided: a window on the opposite side of an edge does not count as a window of the room.
Unfortunately, students will experience huge discomfort when their privacy is watched by someone else through the window. Total discomfort is the number of set of students $\{a,b\},ドル such that $a$ and $b$ can see each other’s privacy through the window.
Precisely, if an edge has windows on both sides, total discomfort increases by the product of the number of people living in two houses sharing the window.
You’re given $w_{i,j},ドル and $p_{i,j},ドル the number of people living in the room $(i,j)$. Your task is to find the minimum total discomfort that can be achieved by arranging the windows properly.
The first line contains the size of the grid, $N$ and $M$.
Following $N$ lines contains $M$ space-separated integers $p_{i,j}$.
Following $N$ lines contains $M$ space-separated integers $w_{i,j}$.
Output the minimum total discomfort.
4 3 1 7 10 7 2 8 7 9 10 4 6 4 3 3 3 3 2 4 4 3 4 2 2 3
178
4 3 2 2 9 9 8 4 8 4 5 7 5 2 0 1 0 1 0 1 0 0 1 0 1 0
0
University > KAIST > KAIST ICPC Mock Competition > 2022 KAIST 12th ICPC Mock Competition M번
Camp > Petrozavodsk Programming Camp > Winter 2023 > Day 4: KAIST+KOI Contest, Grand Prix of Korea M번