結果

問題 No.1587 012 Matrix
ユーザー chineristACchineristAC
提出日時 2021-07-08 23:02:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 80 ms / 1,000 ms
コード長 2,253 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 70,528 KB
最終ジャッジ日時 2024-07-01 13:06:59
合計ジャッジ時間 2,761 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
56,192 KB
testcase_01 AC 53 ms
56,192 KB
testcase_02 AC 53 ms
55,936 KB
testcase_03 AC 53 ms
55,936 KB
testcase_04 AC 52 ms
55,936 KB
testcase_05 AC 53 ms
55,936 KB
testcase_06 AC 52 ms
56,064 KB
testcase_07 AC 52 ms
55,936 KB
testcase_08 AC 56 ms
61,184 KB
testcase_09 AC 57 ms
61,184 KB
testcase_10 AC 60 ms
63,232 KB
testcase_11 AC 64 ms
64,000 KB
testcase_12 AC 65 ms
64,640 KB
testcase_13 AC 68 ms
65,536 KB
testcase_14 AC 70 ms
66,176 KB
testcase_15 AC 71 ms
66,944 KB
testcase_16 AC 72 ms
67,456 KB
testcase_17 AC 76 ms
68,864 KB
testcase_18 AC 77 ms
69,248 KB
testcase_19 AC 77 ms
69,504 KB
testcase_20 AC 79 ms
70,528 KB
testcase_21 AC 80 ms
70,016 KB
testcase_22 AC 52 ms
55,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import permutations
from math import gcd,log

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

from heapq import heappush, heappop
class MinCostFlow:
    INF = 10**18

    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap, cost):
        forward = [to, cap, cost, None]
        backward = forward[3] = [fr, 0, -cost, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def flow(self, s, t, f):
        N = self.N; G = self.G
        INF = MinCostFlow.INF

        res = 0
        H = [0]*N
        prv_v = [0]*N
        prv_e = [None]*N

        d0 = [INF]*N
        dist = [INF]*N

        while f:
            dist[:] = d0
            dist[s] = 0
            que = [(0, s)]

            while que:
                c, v = heappop(que)
                if dist[v] < c:
                    continue
                r0 = dist[v] + H[v]
                for e in G[v]:
                    w, cap, cost, _ = e
                    if cap > 0 and r0 + cost - H[w] < dist[w]:
                        dist[w] = r = r0 + cost - H[w]
                        prv_v[w] = v; prv_e[w] = e
                        heappush(que, (r, w))
            if dist[t] == INF:
                return None

            for i in range(N):
                H[i] += dist[i]

            d = f; v = t
            while v != s:
                d = min(d, prv_e[v][1])
                v = prv_v[v]
            f -= d
            res += d * H[t]
            v = t
            while v != s:
                e = prv_e[v]
                e[1] -= d
                e[3][1] += d
                v = prv_v[v]
        return res

N = int(input())

ans = [["0" for j in range(N)] for i in range(N)]
k = N//2
for i in range(k):
    for j in range(N-1,N-2-i,-1):
        ans[i][j] = "1"
for i in range(k,N):
    for j in range(k,N):
        ans[i][j] = "2"
    for j in range(k):
        ans[i][j] = "1"
    for j in range(k-1,k-2-(i-k),-1):
        ans[i][j] = "2"

for i in range(N):
    print("".join(ans[i]))
0