結果

問題 No.1492 01文字列と転倒
ユーザー chineristACchineristAC
提出日時 2021-04-30 21:36:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,433 ms / 4,000 ms
コード長 2,041 bytes
コンパイル時間 713 ms
コンパイル使用メモリ 87,292 KB
実行使用メモリ 283,524 KB
最終ジャッジ日時 2023-09-26 04:39:33
合計ジャッジ時間 15,704 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 110 ms
74,800 KB
testcase_01 AC 110 ms
74,572 KB
testcase_02 AC 1,433 ms
282,684 KB
testcase_03 AC 1,340 ms
279,752 KB
testcase_04 AC 1,258 ms
274,256 KB
testcase_05 AC 1,078 ms
245,228 KB
testcase_06 AC 1,126 ms
258,292 KB
testcase_07 AC 1,214 ms
283,524 KB
testcase_08 AC 1,194 ms
282,604 KB
testcase_09 AC 117 ms
78,984 KB
testcase_10 AC 112 ms
74,500 KB
testcase_11 AC 113 ms
74,444 KB
testcase_12 AC 112 ms
74,284 KB
testcase_13 AC 112 ms
74,448 KB
testcase_14 AC 1,132 ms
261,984 KB
testcase_15 AC 132 ms
79,764 KB
testcase_16 AC 160 ms
81,768 KB
testcase_17 AC 1,074 ms
244,912 KB
testcase_18 AC 161 ms
81,724 KB
testcase_19 AC 127 ms
79,900 KB
testcase_20 AC 151 ms
81,688 KB
testcase_21 AC 916 ms
203,852 KB
testcase_22 AC 156 ms
81,864 KB
testcase_23 AC 143 ms
81,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegmentTree:
    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        self.size = n
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] += x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        if r==self.size:
            r = self.num

        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

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.buffer.readline()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

mod = 10**9 + 7

N,M = mi()
mod = M
dp = [[0 for k in range(N*(N+1)//2+1)] for j in range(N+1)]
dp[0][0] = 1

for n in range(2*N):
    ndp = [[0 for k in range(N*(N+1)//2+1)] for j in range(N+1)]
    for i in range(min(n+1,N+1)):
        j = n - i
        for k in range(N*(N+1)//2+1):
            if not dp[i][k]:
                continue
            if i!=N and k+j<=N*(N+1)//2:
                ndp[i+1][k+j] += dp[i][k]
                ndp[i+1][k+j] %= mod
            if j!=N and i>=j+1:
                ndp[i][k] += dp[i][k]
                ndp[i][k] %= mod

    dp = ndp

for inv in range(N*(N+1)//2+1):
    print(dp[N][inv])
for inv in range(N*(N+1)//2+1,N**2+1):
    print(0)
0