結果
問題 | No.1873 Bracket Swapping |
ユーザー | chineristAC |
提出日時 | 2022-03-12 01:37:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 450 ms / 2,000 ms |
コード長 | 2,571 bytes |
コンパイル時間 | 283 ms |
コンパイル使用メモリ | 82,152 KB |
実行使用メモリ | 83,284 KB |
最終ジャッジ日時 | 2024-09-16 05:44:44 |
合計ジャッジ時間 | 8,117 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
68,924 KB |
testcase_01 | AC | 55 ms
69,308 KB |
testcase_02 | AC | 63 ms
73,112 KB |
testcase_03 | AC | 131 ms
82,428 KB |
testcase_04 | AC | 111 ms
82,252 KB |
testcase_05 | AC | 112 ms
82,208 KB |
testcase_06 | AC | 258 ms
82,732 KB |
testcase_07 | AC | 61 ms
72,788 KB |
testcase_08 | AC | 416 ms
83,284 KB |
testcase_09 | AC | 450 ms
83,152 KB |
testcase_10 | AC | 333 ms
82,916 KB |
testcase_11 | AC | 88 ms
82,276 KB |
testcase_12 | AC | 239 ms
82,596 KB |
testcase_13 | AC | 209 ms
82,500 KB |
testcase_14 | AC | 408 ms
82,996 KB |
testcase_15 | AC | 161 ms
82,536 KB |
testcase_16 | AC | 81 ms
78,096 KB |
testcase_17 | AC | 264 ms
82,660 KB |
testcase_18 | AC | 84 ms
82,204 KB |
testcase_19 | AC | 97 ms
82,300 KB |
testcase_20 | AC | 354 ms
82,904 KB |
testcase_21 | AC | 84 ms
82,196 KB |
testcase_22 | AC | 111 ms
82,256 KB |
testcase_23 | AC | 449 ms
82,944 KB |
testcase_24 | AC | 449 ms
82,852 KB |
testcase_25 | AC | 441 ms
83,228 KB |
testcase_26 | AC | 296 ms
82,908 KB |
testcase_27 | AC | 403 ms
82,996 KB |
testcase_28 | AC | 111 ms
82,376 KB |
testcase_29 | AC | 57 ms
67,964 KB |
ソースコード
import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 return (g1[n] * g2[r] % mod) * g2[n-r] % mod mod = 998244353 N = 2*10**5 g1 = [1]*(N+1) g2 = [1]*(N+1) inverse = [1]*(N+1) for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 def poly_eval(f,x): res = 0 for i in range(len(f)): res += f[i] * pow(x,i) return res def add(f,g): res = [0 for i in range(max(len(f),len(g)))] for i in range(len(f)): res[i] += f[i] for j in range(len(g)): res[j] += g[j] return res def mul(f,g): res = [0 for i in range(len(f)+len(g)-1)] for i in range(len(f)): for j in range(len(g)): res[i+j] += f[i] * g[j] return res def mat_mul(X,Y): n,m = len(X),len(Y[0]) res = [[0 for j in range(m)] for i in range(n)] for i in range(n): for j in range(m): for k in range(len(Y)): res[i][j] += X[i][k] * Y[k][j] res[i][j] %= mod return res S = input() K = int(input()) n = len(S)//2 left = set([i for i in range(2*n) if S[i]=="("]) right = set([i for i in range(2*n) if S[i]==")"]) dp = [[0 for k in range(n+1)] for j in range(n+1)] dp[0][0] = 1 for i in range(2*n): ndp = [[0 for k in range(n+1)] for j in range(n+1)] for j in range(n+1): for k in range(n+1): if not dp[j][k]: continue """ (にする """ if i not in left and j < n and k < n: ndp[j+1][k+1] += dp[j][k] ndp[j+1][k+1] %= mod elif j < n: ndp[j+1][k] += dp[j][k] ndp[j+1][k] %= mod """ )にする """ if j!=0: ndp[j-1][k] += dp[j][k] ndp[j-1][k] %= mod dp = ndp A = [[0 for j in range(n+1)] for i in range(n+1)] for i in range(n+1): if i!=0: A[i-1][i] = i*i A[i][i] = 2*i*(n-i) + n*(n-1) if i!=n: A[i+1][i] = (n-i)*(n-i) E = [[dp[0][i]] for i in range(n+1)] while K: if K&1: E = mat_mul(A,E) A = mat_mul(A,A) K >>= 1 print(E[0][0])