提出 #76576195


ソースコード 拡げる

from atcoder.maxflow import MFGraph

N, M = map(int, input().split())
S = [list(input().strip()) for _ in range(N)]
s = N * M
t = s + 1
G = MFGraph(t + 1)

def enc(i, j):
    return i*M + j

def dec(num):
    i = num // M
    j = num % M
    return i, j

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]

for i in range(N):
    for j in range(M):
        if S[i][j] == '#':
            continue
        if (i + j) % 2 == 0:
            G.add_edge(s, enc(i, j), 1)
            for d in range(4):
                ni, nj = i + dy[d], j + dx[d]
                if not(0 <= ni < N and 0 <= nj < M) or S[ni][nj] == '#':
                    continue
                G.add_edge(enc(i, j), enc(ni, nj), 1)
        else:
            G.add_edge(enc(i, j), t, 1)

print(G.flow(s, t))
for e in G.edges():
    if e.src == s or e.dst == t or e.flow == 0:
        continue
    ai, aj = dec(e.src)
    bi, bj = dec(e.dst)
    if ai + 1 == bi:
        S[ai][aj] = 'v'
        S[bi][bj] = '^'
    elif bi + 1 == ai:
        S[ai][aj] = '^'
        S[bi][bj] = 'v'
    elif aj + 1 == bj:
        S[ai][aj] = '>'
        S[bi][bj] = '<'
    else:
        S[ai][aj] = '<'
        S[bi][bj] = '>'

for s in S:
    print(''.join(s))

提出情報

提出日時
問題 D - Maxflow
ユーザ taka_hito
言語 Python (PyPy 3.11-v7.3.20)
得点 100
コード長 1250 Byte
結果 AC
実行時間 216 ms
メモリ 126372 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 100 / 100
結果
AC × 1
AC × 19
セット名 テストケース
Sample 00-sample-01.txt
All 00-sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt
ケース名 結果 実行時間 メモリ
00-sample-01.txt AC 129 ms 110532 KiB
01-01.txt AC 130 ms 110144 KiB
01-02.txt AC 129 ms 110596 KiB
01-03.txt AC 132 ms 110540 KiB
01-04.txt AC 130 ms 110464 KiB
01-05.txt AC 135 ms 111292 KiB
01-06.txt AC 131 ms 110492 KiB
01-07.txt AC 199 ms 122940 KiB
01-08.txt AC 149 ms 112592 KiB
01-09.txt AC 137 ms 112040 KiB
01-10.txt AC 154 ms 113268 KiB
01-11.txt AC 133 ms 111168 KiB
01-12.txt AC 203 ms 126372 KiB
01-13.txt AC 216 ms 119804 KiB
01-14.txt AC 213 ms 118100 KiB
01-15.txt AC 191 ms 114408 KiB
01-16.txt AC 137 ms 112704 KiB
01-17.txt AC 208 ms 117812 KiB
01-18.txt AC 213 ms 117892 KiB