CSES - Putka Open 2020 – 1/5 - Results
Submission details
Task:Ruudukko
Sender:osku91
Submission time:2020-09-06 19:58:54 +0300
Language:Python3 (CPython3)
Status:READY
Result:46
Feedback
groupverdictscore
#1ACCEPTED16
#2ACCEPTED30
#30
Test results
testverdicttimegroup
#1ACCEPTED0.04 s1, 2, 3details
#2ACCEPTED0.04 s1, 2, 3details
#3ACCEPTED0.04 s1, 2, 3details
#4ACCEPTED0.04 s1, 2, 3details
#5ACCEPTED0.04 s1, 2, 3details
#6ACCEPTED0.04 s1, 2, 3details
#7ACCEPTED0.07 s2, 3details
#8ACCEPTED0.07 s2, 3details
#9ACCEPTED0.07 s2, 3details
#10ACCEPTED0.07 s2, 3details
#11ACCEPTED0.07 s2, 3details
#12ACCEPTED0.07 s2, 3details
#13--3details
#14--3details
#15--3details
#16--3details
#17--3details
#18--3details

Code

import json
import time

n = int(input(''))

table = []
for y in range(n):
    table.append(input(''))

position_values = [[None for y in range(n)] for x in range(n)]

class Container():
    def __init__(self, data):
        self.data = data

    def increment(self):
        self.data = [
            (a + 1, b + 1)
            for a, b in self.data
        ]

    def compress(self):
        sorted_data = sorted(self.data)

        compressed_data = []

        i = 0
        while i < len(sorted_data):
            cur_min = sorted_data[i][0]
            cur_max = sorted_data[i][1]
            while True:
                i += 1
                if i == len(sorted_data):
                    break

                this_min = sorted_data[i][0]
                this_max = sorted_data[i][1]
                if this_min - 1 > cur_max:
                    break
                cur_max = max(cur_max, this_max)

            compressed_data.append((cur_min, cur_max))

        self.data = compressed_data

        pass

    def value(self):
        self.compress()
        value = list(set(sum([list(range(a, b + 1)) for a, b in self.data], [])))
        # print('value', value)
        return value

    @classmethod
    def from_one(cls, other, this_adds):
        item = cls(other.data)
        if this_adds:
            item.increment()
        return item

    @classmethod
    def from_two(cls, other1, other2, this_adds):
        item = cls(other1.data + other2.data)
        item.compress()
        if this_adds:
            item.increment()
        return item



for x in range(n):
    for y in range(n):
        table_value = table[x][y]
        new_container = None
        if x == 0 and y == 0:
            new_container = Container([(0, 0)]) if table_value == '.' else Container([(1, 1)])
        elif y == 0:
            new_container = Container.from_one(
                position_values[x - 1][y],
                table_value == 'o'
            )
        elif x == 0:
            new_container = Container.from_one(
                position_values[x][y - 1],
                table_value == 'o'
            )
        else:
            new_container = Container.from_two(
                position_values[x][y - 1],
                position_values[x - 1][y],
                table_value == 'o'
            )

        position_values[x][y] = new_container


# Vastaukset:
# 280
# 564


solution: Container = position_values[n-1][n-1]
print(len(solution.value()))

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
..........
..........
..........
..........
...

correct output
1

user output
1

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
o.o.......
..........
.o...o.oo.
..o...o.oo
...

correct output
9

user output
9

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
o......o..
oo.oo.....
oooo....oo
o.......oo
...

correct output
14

user output
14

Test 4

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
..ooooo.oo
.ooo.o..oo
.....ooo.o
ooo.ooo.oo
...

correct output
12

user output
12

Test 5

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
oooooooooo
ooo....ooo
.oo.oo.ooo
oooooooooo
...

correct output
10

user output
10

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

input
10
oooooooooo
oooooooooo
oooooooooo
oooooooooo
...

correct output
1

user output
1

Test 7

Group: 2, 3

Verdict: ACCEPTED

input
100
.................................

correct output
1

user output
1

Test 8

Group: 2, 3

Verdict: ACCEPTED

input
100
.........o.....o.........o..o....

correct output
114

user output
114

Test 9

Group: 2, 3

Verdict: ACCEPTED

input
100
oo..oo.oo..o...o..o.o..o.........

correct output
151

user output
151

Test 10

Group: 2, 3

Verdict: ACCEPTED

input
100
o..o.ooo..oo.o.o.o..o.o..o..oo...

correct output
143

user output
143

Test 11

Group: 2, 3

Verdict: ACCEPTED

input
100
oo..oooooooooooo.oooo.o.o.oooo...

correct output
115

user output
115

Test 12

Group: 2, 3

Verdict: ACCEPTED

input
100
oooooooooooooooooooooooooooooo...

correct output
1

user output
1

Test 13

Group: 3

Verdict:

input
1000
.................................

correct output
1

user output
(empty)

Test 14

Group: 3

Verdict:

input
1000
o..........o...o...o...o.........

correct output
1121

user output
(empty)

Test 15

Group: 3

Verdict:

input
1000
.o.............o....o.o......o...

correct output
1583

user output
(empty)

Test 16

Group: 3

Verdict:

input
1000
oooooo.oooooo.....oooo..o...o....

correct output
1574

user output
(empty)

Test 17

Group: 3

Verdict:

input
1000
ooooo.oo.oooooooooo...o...oo.....

correct output
1147

user output
(empty)

Test 18

Group: 3

Verdict:

input
1000
oooooooooooooooooooooooooooooo...

correct output
1

user output
(empty)