結果

問題 No.459 C-VS for yukicoder
ユーザー maspymaspy
提出日時 2020-03-18 21:25:09
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 216 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 14,572 KB
最終ジャッジ日時 2024-12-14 02:30:21
合計ジャッジ時間 5,779 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W, N = map(int, readline().split())
cols = [0] * W
for _ in range(H):
    S = readline().rstrip()
    for i, x in enumerate(S):
        if x == ord('#'):
            cols[i] += 1
C = list(map(int, read().split()))

use = [0 for _ in range(N)]


def to_string(n):
    n, a = divmod(n, 4)
    c, b = divmod(n, 4)
    ch = '.', '#'
    rows = [None] * 3
    rows[0] = ch[a > 0] + ch[b > 0] + ch[c > 0]
    a -= 1
    b -= 1
    c -= 1
    rows[1] = ch[a > 0] + ch[b > 0] + ch[c > 0]
    a -= 1
    b -= 1
    c -= 1
    rows[2] = ch[a > 0] + ch[b > 0] + ch[c > 0]
    return '\n'.join(rows)


col_to_i = [[] for _ in range(W + 10)]
for i, x in enumerate(C):
    col_to_i[x].append(i)

for col in range(W):
    for i in col_to_i[col - 2]:
        if cols[col] and not use[i]:
            use[i] = 16
            cols[col] -= 1
    for i in col_to_i[col - 1]:
        if cols[col] and not use[i]:
            use[i] = 4
            cols[col] -= 1
    for i in col_to_i[col]:
        if cols[col] and not use[i]:
            use[i] = 1
            cols[col] -= 1


for col in range(W):
    for i in col_to_i[col - 2]:
        n = min(cols[col], 3 - use[i] //16)
        cols[col] -= n
        use[i] += n * 16
    for i in col_to_i[col - 1]:
        n = min(cols[col], 3 - ((use[i] % 16) // 4))
        cols[col] -= n
        use[i] += 4 * n
    for i in col_to_i[col]:
        n = min(cols[col], 3 - (use[i] % 4))
        cols[col] -= n
        use[i] += n

for n in use:
    print(to_string(n))
0