結果

問題 No.1608 Yet Another Ants Problem
ユーザー sash0sash0
提出日時 2021-07-20 00:29:34
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 4,156 bytes
コンパイル時間 3,068 ms
コンパイル使用メモリ 226,968 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 12:44:06
合計ジャッジ時間 5,981 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 26 ms
4,376 KB
testcase_15 AC 26 ms
4,376 KB
testcase_16 AC 26 ms
4,376 KB
testcase_17 AC 26 ms
4,376 KB
testcase_18 AC 26 ms
4,376 KB
testcase_19 AC 4 ms
4,380 KB
testcase_20 AC 12 ms
4,376 KB
testcase_21 AC 12 ms
4,384 KB
testcase_22 AC 8 ms
4,376 KB
testcase_23 AC 25 ms
4,376 KB
testcase_24 AC 26 ms
4,380 KB
testcase_25 AC 26 ms
4,380 KB
testcase_26 AC 26 ms
4,376 KB
testcase_27 AC 26 ms
4,380 KB
testcase_28 AC 26 ms
4,380 KB
testcase_29 AC 26 ms
4,376 KB
testcase_30 AC 26 ms
4,376 KB
testcase_31 AC 26 ms
4,380 KB
testcase_32 AC 25 ms
4,380 KB
testcase_33 AC 26 ms
4,376 KB
testcase_34 AC 26 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// clang-format off
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcountll
#define ffs __builtin_ffsll
#define ctz __builtin_ctzll
#define clz __builtin_clz
#define clzll __builtin_clzll
#define all(a) (a).begin(), (a).end()

using namespace std;
using namespace __gnu_pbds;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
template <typename T> bool getf(T flag, size_t i) { return (flag>>i) & 1; }
template <typename T> T setf(T flag, size_t i) { return flag | (T(1)<<i); }
template <typename T> T unsetf(T flag, size_t i) { return flag & ~(T(1)<<i); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

template <long long mod>
long long mod_pow(long long a, long long b) {
    if (b == 0) return 1;
    long long ret = mod_pow<mod>(a, b / 2);
    ret = ret * ret % mod;
    if (b % 2 == 1) ret = a * ret % mod;
    return ret;
}

template <long long mod>
struct Comb {
    int n;
    vector<long long> fact, inv;

    Comb(int n)
        : n(n), fact(n + 1, 0), inv(n + 1, 0) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
        inv[n] = mod_pow<mod>(fact[n], mod - 2);
        for (int i = n; i >= 1; i--) inv[i - 1] = inv[i] * i % mod;
    }

    long long operator()(int m, int k) {
        assert(!(m > n || m < k || k < 0));
        return fact[m] * inv[m - k] % mod * inv[k] % mod;
    }
};

const ll MOD = 998244353;

int main() {
    fastio();

    int n, l;
    cin >> n >> l;
    vi a(n);
    forn(i, n) cin >> a[i];

    Comb<MOD> comb(n + 1);

    vec<ll> ans(n);

    auto calc = [&](bool b) {
        // iが最後に右から落ちるような場合の数
        for (int i = n - 1; i >= 0; i--) {
            int d = l - a[i]; // 右端までの距離

            int k; // iより右側にある要素のうち、左端までの距離が(dより大きい)or(d以上)のもの最左の位置
            bool ok; // 左隣の要素の左端までの距離が(d以上)or(dより大きい)かをチェック
            if (b) {
                k = upper_bound(all(a), d) - a.begin();
                ok = i == 0 or a[i - 1] <= d;
            } else {
                k = lower_bound(all(a), d) - a.begin();
                ok = i == 0 or a[i - 1] < d;
            }
            k = max(k, i + 1);

            // iより右にある要素のうち、自由に向きを選んで良い(左向きでも良い)ものの数
            int c = k - i - 1;

            if (ok) {
                // j: 左向きのものの数
                for (int j = 0; j <= c; j++) {
                    // 右向きのものの数
                    int x = n - i - j;
                    ans[n - x] = (ans[n - x] + comb(c, j)) % MOD;
                }
            }
        }
    };

    calc(false);
    for (auto& x : a) x = l - x;
    reverse(all(a));
    reverse(all(ans));
    calc(true);
    reverse(all(ans));

    for (auto x : ans) {
        cout << x << "\n";
    }

    return 0;
}
0