結果
問題 |
No.1885 Flat Permutation
|
ユーザー |
|
提出日時 | 2022-08-04 00:03:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 1,112 bytes |
コンパイル時間 | 4,188 ms |
コンパイル使用メモリ | 253,476 KB |
最終ジャッジ日時 | 2025-01-30 17:23:50 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/all> using namespace atcoder; #define ll long long #define rep(i, n) for (int i = 0; i < (n); i++) #define P pair<int, int> #define LP pair<ll, ll> #define fi first #define se second #define pb push_back #define eb emplace_back #define all(s) s.begin(), s.end() #define rall(s) s.rbegin(), s.rend() template<class T> void chmax(T& a, T b) { a = max(a, b); }; template<class T> void chmin(T& a, T b) { a = min(a, b); }; using mint = modint998244353; int main() { int n, x, y; cin >> n >> x >> y; if (x > y) swap(x,y); if (x == 1 && y == 2) { cout << 1 << endl; return 0; } if (n==2&&x==1&&y==2) { cout << 1 << endl; return 0; } if (x ==n-1 && y == n) { cout << 1 << endl; return 0; } if (y-1==x) { cout << 0 << endl; return 0; } int d = y-1-(x+1)+1; if (x == 1) d++; if (y == n) d++; vector dp(n+1, vector<mint>(2)); dp[1][0] = 1; for (int i = 1; i < n; i++) { dp[i+1][0] = dp[i][0]+dp[i][1]; dp[i+1][1] = dp[i-1][0]; } cout << dp[d][0].val() << endl; return 0; }