結果
問題 |
No.1885 Flat Permutation
|
ユーザー |
|
提出日時 | 2022-03-25 22:32:58 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 20 ms / 2,000 ms |
コード長 | 3,315 bytes |
コンパイル時間 | 1,898 ms |
コンパイル使用メモリ | 194,584 KB |
最終ジャッジ日時 | 2025-01-28 12:20:41 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++) #define all(x) x.begin(),x.end() #define STRINGIFY(n) #n #define TOSTRING(n) STRINGIFY(n) #define PREFIX "#" TOSTRING(__LINE__) "| " #define debug(x) \ { \ std::cout << PREFIX << #x << " = " << x << std::endl; \ } std::ostream& output_indent(std::ostream& os, int ind) { for(int i = 0; i < ind; i++) os << " "; return os; } template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p); template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v); template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) { return (os << "(" << p.first << ", " << p.second << ")"); } template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) { os << "["; for(int i = 0;i < v.size();i++) os << v[i] << ", "; return (os << "]"); } template<class T> static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); } template<class... Tail> static inline auto ndvec(size_t&& n, Tail&&... tail) { return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...)); } i64 gcd(i64 a, i64 b) { if(b == 0) return a; return gcd(b, a % b); } #include <iostream> using i64 = long long; template<i64 M> struct modint { i64 a; constexpr modint(const i64 x = 0): a((x%M+M)%M){} constexpr i64 value() const { return a; } constexpr modint inv() const { return this->pow(M-2); } constexpr modint pow(i64 r) const { modint ans(1); modint aa = *this; while(r) { if(r & 1) ans *= aa; aa *= aa; r >>= 1; } return ans; } constexpr modint& operator=(const i64 r) { a = (r % M + M) % M; return *this; } constexpr modint& operator+=(const modint r) { a += r.a; if(a >= M) a -= M; return *this; } constexpr modint& operator-=(const modint r) { a -= r.a; if(a < 0) a += M; return *this; } constexpr modint& operator*=(const modint r) { a = a * r.a % M; return *this; } constexpr modint& operator/=(const modint r) { (*this) *= r.inv(); return *this; } constexpr modint operator+(const modint r) const { return modint(*this) += r; } constexpr modint operator-(const modint r) const { return modint(*this) -= r; } constexpr modint operator*(const modint r) const { return modint(*this) *= r; } constexpr modint operator/(const modint r) const { return modint(*this) /= r; } constexpr bool operator!=(const modint r) const { return this->value() != r.value(); } }; template<const i64 M> std::ostream& operator<<(std::ostream& os, const modint<M>& m) { os << m.value(); return os; } using fp = modint<998244353>; int main() { i64 N, X, Y; cin >> N >> X >> Y; { i64 a = std::min(X, Y); i64 b = std::max(X, Y); X = a; Y = b; } // down hill i64 c; if(X == 1) { c = X; } else { c = X + 1; } if(c == Y) { if(Y == N) { cout << 1 << endl; } else { cout << 0 << endl; } return 0; } if(Y == N) { Y++; } vector<fp> dp(Y - c, fp(0)); dp[0] = fp(1); rep(i,1,dp.size()) { dp[i] += dp[i - 1]; if(i - 3 >= 0) { dp[i] += dp[i - 3]; } } cout << dp.back() << endl; }