結果

問題 No.1885 Flat Permutation
ユーザー gazelle
提出日時 2022-03-25 22:09:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,293 bytes
コンパイル時間 1,938 ms
コンパイル使用メモリ 194,220 KB
最終ジャッジ日時 2025-01-28 12:10:37
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3 WA * 1
other AC * 24 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i, n, m) for (long long i = (n); i < (long long)(m); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr ld eps = 1e-6;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
    os << to_string(p.first) << " " << to_string(p.second);
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
    REP(i, v.size()) {
        if (i) os << " ";
        os << v[i];
    }
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, x, y;
    cin >> n >> x >> y;

    if (x > y) swap(x, y);

    if (x + 1 == y) {
        if (n == 2) {
            cout << 1 << endl;
            return 0;
        }
        if (x == 1 || y == n) {
            cout << 1 << endl;
            return 0;
        }

        cout << 0 << endl;
        return 0;
    }

    vector<ll> dp(y - x + 1, 0);
    dp[0] = 1;
    FOR(i, 1, y - x + 1) {
        dp[i] += dp[i - 1];
        if (i >= 3) dp[i] += dp[i - 3];
        dp[i] %= mod;
    }
    cout << dp[y - x] << endl;
    return 0;
}
0