33OJ
登录 注册

#P17822. [COCI 2026/2027 #1] Kockice

    ID: 20476 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>模拟贪心排序COCI(克罗地亚)2026

[COCI 2026/2027 #1] Kockice

Problem Description

Mr. Malnar is playing a game with dice. The rules are simple. First, each player rolls any number of dice. Then, the player may choose to flip at most kk dice so that the sides opposite the ones currently facing up become visible, or choose not to flip any dice at all. It is well known that the numbers on any pair of opposite sides of a die add up to 77 (e.g., 22 and 55 are on opposite sides). Each player's score is the sum of the numbers showing on the dice after all flips have been made. The player with the highest score wins.

Mr. Malnar really wants to win, so he has decided to cheat. He secretly took a photo of the dice on the table and sent it to you, asking for help. The photo has dimensions 3×n3\times n. Since the dice are the same colour as the table, their outlines cannot be seen. Fortunately, the dots on the dice are clearly visible. Each dot is represented by an o, while each empty space is represented by a -. The six sides of a die are represented in the photo as shown below:

---   o--   o--   o-o   o-o   o-o
-o-   ---   -o-   ---   -o-   o-o
---   --o   --o   o-o   o-o   o-o

 1     2     3     4     5     6

Quick! Mr. Malnar needs your help! What is the maximum score he can achieve?

Input Format

The first line contains two natural numbers, nn (3≤n≤10003\le n\le 1000) and kk (0≤k≤10000\le k\le 1000), representing the width of the photo and the maximum number of dice Mr. Malnar may flip.

Each of the next three lines contains a string of length nn, consisting only of - and o, representing the photo you received. The photo will always display at least one rolled die.

The sides of the dice will appear only in the orientations shown in the statement, i.e., they cannot be rotated. The photo will always represent a valid arrangement of dice that could result from rolling them onto the table.

Output Format

In the first and only line, write one number - the maximum score Mr. Malnar can achieve.

3 1
o-o
---
o-o
4
11 4
-o-o----o--
--o------o-
-o-o------o
9
17 2
o--o-o-------o---
-o-o-o--o--------
--oo-o---------o-
20

Hint

Clarification of the first example

Mr. Malnar rolled one die and it showed the number 44. Since k=1k=1, Mr. Malnar can flip over the one die. The number opposite of 44 is 33 (because 4+3=74+3=7) so if he flips the die he will get a score of 33. However, it is optimal to not flip the die because the sum is bigger when the dice shows 44 than when the dice shows 33.

Clarification of the second example

Mr. Malnar rolled two dice and got the numbers 55 and 33. He can flip up to four dice; however, there are only two dice on the table so he can either flip one die, flip both of them, or not flip any. If he doesn't flip any die, he will get a score of 5+3=85+3=8. If he only flips the die showing 55, its value will change to 22 making his score 2+3=52+3=5. If he only flips the die showing 33, its value will change to 44 making his score 4+5=94+5=9. If he flips both dice, they will show the numbers 22 and 44 making his score 66. Therefore, the maximum score he can achieve is 99 - this can be achieved by flipping the die showing 33.

Clarification of the third example

Mr. Malnar rolled four dice and got the value 33, 66, 11 and 22, in that order as seen on the photo. He can flip up to two of them. A maximum score is achieved if he flips the die showing 11 (which turns into 66) and the die showing 22 (which turns into 55). This changes his score from 3+6+1+2=123+6+1+2=12 to 3+6+6+5=203+6+6+5=20.

Scoring

Subtask Points Constraints
1 9 n=3n=3
2 10 All the dice show either 11 or 33.
3 13 k=0k=0
4 18 No additional constraints.