CSES - Datatähti 2023 alku - Results
Submission details
Task:Lehmät
Sender:Tobdu
Submission time:2022-11-01 16:11:28 +0200
Language:PyPy3
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2details
#20.04 s1, 2details
#3ACCEPTED0.04 s1, 2details
#4ACCEPTED0.04 s1, 2details
#50.04 s1, 2details
#60.04 s2details
#70.04 s2details
#80.04 s2details
#90.04 s2details

Code

# @ cow
# * fence

height, width = input().split(" ")

meadow = []

for i in range(int(height)):
    meadow.append(input()[:int(width)])

fence_vertical_start_pos   = -1
fence_horizontal_start_pos = -1
fence_width                = -1
fence_height               = -1

# Get the size and position of the fence
for row in range(int(len(meadow))):
    if meadow[row].count("*") > 2:
        if fence_vertical_start_pos == -1:
            fence_vertical_start_pos = row

            for col in range(int(len(meadow[row]))):
                if meadow[row][col] == "*":
                    if fence_horizontal_start_pos != -1:
                        continue

                    fence_horizontal_start_pos = col
                else:
                    if fence_horizontal_start_pos == -1:
                        continue

                    fence_width = col - fence_horizontal_start_pos


        else:
            fence_height = row - fence_vertical_start_pos

# Get the area inside the fence
cowmap = []

for y in range(int(len(meadow))):
    if y > fence_vertical_start_pos and y < fence_vertical_start_pos + fence_height:
        cowmap.append(meadow[y][fence_horizontal_start_pos + 1:fence_horizontal_start_pos + fence_width - 1])

# Count the total amount of cows
cow_total_count = 0
for i in cowmap:
    cow_total_count += i.count("@")

print(cow_total_count)

    

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
3 3
***
*.*
***

correct output
0

user output
0

Test 2

Group: 1, 2

Verdict:

input
3 3
***
*@*
***

correct output
1

user output
0

Test 3

Group: 1, 2

Verdict: ACCEPTED

input
5 10
...@......
..******..
@.*@@@@*.@
..******..
...

correct output
4

user output
4

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
10 10
@@...@.@@@
..@@.@@..@
@.*******@
..*@....*.
...

correct output
11

user output
11

Test 5

Group: 1, 2

Verdict:

input
10 10
**********
*@@@@@@@@*
*@@@@@@@@*
*@@@@@@@@*
...

correct output
64

user output
56

Test 6

Group: 2

Verdict:

input
100 100
.........................@.......

correct output
60

user output
64

Test 7

Group: 2

Verdict:

input
100 100
..@@..........@......@....@@.....

correct output
1507

user output
1544

Test 8

Group: 2

Verdict:

input
100 100
.@..@@..@@.@..@..@..@@..@..@.....

correct output
3348

user output
3464

Test 9

Group: 2

Verdict:

input
100 100
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@...

correct output
7225

user output
7735