結果

問題 No.1885 Flat Permutation
ユーザー iorion
提出日時 2022-03-25 22:04:40
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 467 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2024-10-14 06:00:17
合計ジャッジ時間 2,987 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 RE * 1
other AC * 25 RE * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

from functools import lru_cache
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 998244353

@lru_cache(None)
def solve2(n):
    if n <= 0:
        return 0
    if n <= 3:
        return 1
    return (solve2(n - 1) + solve2(n - 3)) % MOD

def solve(n, x, y):
    if x > y:
        return solve(n, y, x)
    if x > 1:
        return solve(n - x, 1, y - x)
    if y < n:
        return solve(y - 1, x, y - 1)
    return solve2(n)

print(solve(*map(int, input().split())))
0