Submission #5541288


Source Code Expand

Copy
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N, M = MI()
    s = ["#"*M]
    up = [[0] * (M+2) for _ in range(N+2)]
    left = [[0]*(M+2) for _ in range(N+2)]
    right = [[0]*(M+2) for _ in range(N+2)]
    down = [[0] * (M+2) for _ in range(N+2)]
    for i in range(N):
        a = ST()
        s.append("#"+a+"#")
    s += ["#" * M]
    for i in range(1, N+1):
        for j in range(1, M+1):
            """if (i, j) == (0, 0):
                if s[i][j] == ".":
                    up[i][j] = 1
                    left[i][j] = 1"""
            if s[i][j] == "#":
                continue
            else:
                up[i][j] = up[i-1][j] + 1
                left[i][j] = left[i][j-1] + 1
    for i in range(1, N+1)[::-1]:
        for j in range(1, M+1)[::-1]:
            if s[i][j] == "#":
                continue
            else:
                down[i][j] = down[i+1][j] + 1
                right[i][j] = right[i][j+1] + 1
    ans = 0
    for i in range(1, N+1):
        for j in range(1, M + 1):
            if s[i][j] == ".":
                """print((left[i][j-1] + right[i][j+1]),
                      (up[i - 1][j] + down[i + 1][j]), end="")"""
                ans += (left[i][j-1] + right[i][j+1]) * \
                    (up[i - 1][j] + down[i + 1][j])
    print(ans)
    """
    print(*up, sep="\n")
    print()
    print(*down, sep="\n")
    print()
    print(*left, sep="\n")
    print()
    print(*right, sep="\n")
    print(ans)
    """


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task C - 右折
User petite_prog
Language PyPy3 (2.4.0)
Score 400
Code Size 2189 Byte
Status
Exec Time 599 ms
Memory 176776 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 s1.txt, s2.txt, s3.txt
All 400 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt 599 ms 176776 KB
02.txt 593 ms 176520 KB
03.txt 583 ms 176520 KB
04.txt 592 ms 176520 KB
05.txt 551 ms 176520 KB
06.txt 558 ms 176520 KB
07.txt 551 ms 176392 KB
08.txt 575 ms 176392 KB
09.txt 538 ms 176136 KB
10.txt 536 ms 176264 KB
11.txt 527 ms 176264 KB
12.txt 527 ms 176264 KB
13.txt 459 ms 176392 KB
14.txt 460 ms 176264 KB
15.txt 519 ms 176392 KB
16.txt 530 ms 176136 KB
17.txt 387 ms 175752 KB
18.txt 397 ms 175880 KB
19.txt 519 ms 176264 KB
20.txt 522 ms 176520 KB
21.txt 577 ms 176520 KB
22.txt 562 ms 176392 KB
23.txt 567 ms 176264 KB
24.txt 553 ms 176264 KB
25.txt 535 ms 176392 KB
26.txt 541 ms 176264 KB
27.txt 536 ms 176264 KB
28.txt 528 ms 176136 KB
29.txt 168 ms 38256 KB
30.txt 171 ms 38256 KB
31.txt 173 ms 38256 KB
32.txt 170 ms 38256 KB
33.txt 178 ms 38256 KB
34.txt 168 ms 38384 KB
35.txt 167 ms 38256 KB
36.txt 171 ms 38256 KB
s1.txt 167 ms 38256 KB
s2.txt 168 ms 38256 KB
s3.txt 167 ms 38256 KB