結果
問題 |
No.1885 Flat Permutation
|
ユーザー |
![]() |
提出日時 | 2022-03-28 23:21:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 2,000 ms |
コード長 | 1,213 bytes |
コンパイル時間 | 592 ms |
コンパイル使用メモリ | 41,856 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 13:45:13 |
合計ジャッジ時間 | 2,088 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
/* -*- coding: utf-8 -*- * * 1885.cc: No.1885 Flat Permutation - yukicoder */ #include<cstdio> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 200000; const int MOD = 998244353; /* typedef */ /* typedef */ template<const int MOD> struct MI { int v; MI(): v() {} MI(int _v): v(_v % MOD) {} MI(long long _v): v(_v % MOD) {} MI operator+(const MI m) const { return MI(v + m.v); } MI operator-(const MI m) const { return MI(v + MOD - m.v); } MI operator*(const MI m) const { return MI((long long)v * m.v); } MI &operator+=(const MI m) { return (*this = *this + m); } MI &operator-=(const MI m) { return (*this = *this - m); } MI &operator*=(const MI m) { return (*this = *this * m); } }; typedef MI<MOD> mi; /* global variables */ mi dp[MAX_N]; /* subroutines */ /* subroutines */ /* main */ int main() { int n, x, y; scanf("%d%d%d", &n, &x, &y); if (x > y) swap(x, y); if (x > 1) x++; if (y < n) y--; int d = y - x; //printf("d=%d\n", d); if (d < 0) { puts("0"); return 0; } dp[0] = 1; for (int i = 0; i < d; i++) { dp[i + 1] += dp[i]; if (i + 3 <= d) dp[i + 3] += dp[i]; } printf("%d\n", dp[d].v); return 0; }