結果

問題 No.1885 Flat Permutation
ユーザー chineristACchineristAC
提出日時 2022-03-25 23:48:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 971 ms / 2,000 ms
コード長 1,269 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,180 KB
実行使用メモリ 311,624 KB
最終ジャッジ日時 2024-04-22 08:53:00
合計ジャッジ時間 18,286 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
69,732 KB
testcase_01 AC 69 ms
69,492 KB
testcase_02 AC 68 ms
70,836 KB
testcase_03 AC 100 ms
90,684 KB
testcase_04 AC 69 ms
70,652 KB
testcase_05 AC 70 ms
70,108 KB
testcase_06 AC 69 ms
69,628 KB
testcase_07 AC 68 ms
71,200 KB
testcase_08 AC 68 ms
70,864 KB
testcase_09 AC 69 ms
71,344 KB
testcase_10 AC 69 ms
70,540 KB
testcase_11 AC 70 ms
70,180 KB
testcase_12 AC 69 ms
70,132 KB
testcase_13 AC 69 ms
69,812 KB
testcase_14 AC 69 ms
70,392 KB
testcase_15 AC 68 ms
70,196 KB
testcase_16 AC 69 ms
70,380 KB
testcase_17 AC 69 ms
70,376 KB
testcase_18 AC 69 ms
69,976 KB
testcase_19 AC 971 ms
311,608 KB
testcase_20 AC 950 ms
311,124 KB
testcase_21 AC 913 ms
311,056 KB
testcase_22 AC 845 ms
289,108 KB
testcase_23 AC 70 ms
71,160 KB
testcase_24 AC 68 ms
69,576 KB
testcase_25 AC 70 ms
69,984 KB
testcase_26 AC 70 ms
69,804 KB
testcase_27 AC 931 ms
311,612 KB
testcase_28 AC 938 ms
311,624 KB
testcase_29 AC 929 ms
311,444 KB
testcase_30 AC 924 ms
310,748 KB
testcase_31 AC 940 ms
311,220 KB
testcase_32 AC 70 ms
70,544 KB
testcase_33 AC 69 ms
69,620 KB
testcase_34 AC 71 ms
70,112 KB
testcase_35 AC 934 ms
311,456 KB
testcase_36 AC 931 ms
311,316 KB
testcase_37 AC 69 ms
70,900 KB
testcase_38 AC 69 ms
69,904 KB
testcase_39 AC 68 ms
70,920 KB
testcase_40 AC 205 ms
119,820 KB
testcase_41 AC 416 ms
175,704 KB
testcase_42 AC 134 ms
100,708 KB
testcase_43 AC 917 ms
311,284 KB
testcase_44 AC 921 ms
311,348 KB
testcase_45 AC 917 ms
311,320 KB
testcase_46 AC 920 ms
311,160 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

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

sys.setrecursionlimit(3*10**5)

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 = 3*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

N,X,Y = mi()
if X > Y:
    X,Y = Y,X

if X!=1:
    N,X,Y = N-X,1,Y-X
    if Y==1:
        if N==1:
            exit(print(1))
        else:
            exit(print(0))

memo = {(1,1,1):1,(4,1,4):2}
def calc(n,x,y):
    if (n,x,y) in memo:
        return memo[n,x,y]
    
    if y==x+1:
        memo[n,x,y] = 1
        return memo[n,x,y]
    
    res = 0
    if x+1!=y:
        res += calc(n-1,1,y-1)
        res %= mod
    if x+1!=y and x+2!=y and x+3!=y and x+3 <= n:
        res += calc(n-3,1,y-3)
        res %= mod
    memo[n,x,y] = res
    return res

print(calc(N,X,Y))
#print(memo)





0