提出 #68598104


ソースコード 拡げる

//  ↘ ⬇ ⬇ ⬇ ⬇ ⬇ ↙
//  ➡ @roadfromroi ⬅
//  ↗ ⬆ ⬆ ⬆ ⬆ ⬆ ↖
/*
░░░░░░░█▐▓▓░████▄▄▄█▀▄▓▓▓▌█
░░░░░▄█▌▀▄▓▓▄▄▄▄▀▀▀▄▓▓▓▓▓▌█
░░░▄█▀▀▄▓█▓▓▓▓▓▓▓▓▓▓▓▓▀░▓▌█
░░█▀▄▓▓▓███▓▓▓███▓▓▓▄░░▄▓▐█▌
░█▌▓▓▓▀▀▓▓▓▓███▓▓▓▓▓▓▓▄▀▓▓▐█
▐█▐██▐░▄▓▓▓▓▓▀▄░▀▓▓▓▓▓▓▓▓▓▌█▌
█▌███▓▓▓▓▓▓▓▓▐░░▄▓▓███▓▓▓▄▀▐█
█▐█▓▀░░▀▓▓▓▓▓▓▓▓▓██████▓▓▓▓▐█
▌▓▄▌▀░▀░▐▀█▄▓▓██████████▓▓▓▌█▌
▌▓▓▓▄▄▀▀▓▓▓▀▓▓▓▓▓▓▓▓█▓█▓█▓▓▌█▌
█▐▓▓▓▓▓▓▄▄▄▓▓▓▓▓▓█▓█▓█▓█▓▓▓▐█ йоу
 */
#include <iostream>
#include "queue"
#include "vector"
#include "algorithm"
#include "numeric"
#include "climits"
#include "iomanip"
#include "bitset"
#include "cmath"
#include "map"
#include "deque"
#include "array"
#include "set"
#include "random"
#ifndef __APPLE__
#include "bits/stdc++.h"
#endif
#define all(x) x.begin(), x.end()
using namespace std;

template<int M>
struct modint {
    modint() : x(0) {}

    template<class T>
    modint(T n) {
        n %= M;
        if (n < 0) n += M;
        this->x = n;
    }

    modint &operator+=(const modint &r) {
        x += r.x;
        if (x >= M) x -= M;
        return *this;
    }

    modint &operator-=(const modint &r) {
        x -= r.x;
        if (x < 0) x += M;
        return *this;
    }

    modint &operator*=(const modint &r) {
        x = (int) ((long long) x * r.x % M);
        return *this;
    }

    modint &operator--() {
        if (--x == -1) x = M - 1;
        return *this;
    }

    modint &operator++() {
        if (++x == M) x = 0;
        return *this;
    }

    modint operator--(int) {
        modint t = *this;
        --*this;
        return t;
    }

    modint operator++(int) {
        modint t = *this;
        ++*this;
        return t;
    }

    modint operator-() const { return 0 - *this; }

    modint operator+() const { return *this; }

    modint power(long long k = M - 2) const {
        modint f = 1, p = *this;
        while (k > 0) {
            if (k & 1) f *= p;
            p *= p, k >>= 1;
        }
        return f;
    }

    int mod() const { return M; }

    friend modint operator+(modint l, const modint &r) { return l += r; }

    friend modint operator-(modint l, const modint &r) { return l -= r; }

    friend modint operator*(modint l, const modint &r) { return l *= r; }

    friend bool operator==(const modint &l, const modint &r) { return l.x == r.x; }

    friend bool operator!=(const modint &l, const modint &r) { return l.x != r.x; }

    friend ostream &operator<<(ostream &out, const modint &r) { return out << r.x; }

    int x;
};

// using mint = modint<1000000007>;
using mint = modint<998244353>;
mint dps(int n, vector<int> a, vector<int> b, int r) {
    vector<vector<mint>> dp(n + 1, vector<mint>(n + 1));
    vector<vector<int>> dpval(n + 1, vector<int>(n + 1));
    dpval[n][n] = r;
    dp[n][n] = 1;
    for (int i = n; i >= 0; --i) {
        for (int j = n; j >= 0; --j) {
            if (i < j)
                continue;
            if (i + 1 <= n) {
                dpval[i][j] = dpval[i + 1][j] + a[i];
            } else if (j + 1 <= n) {
                dpval[i][j] = dpval[i][j + 1] - b[j];
            }
            if (dpval[i][j] >= 0) {
                if (i + 1 <= n) {
                    dp[i][j] += dp[i + 1][j];
                }
                if (j + 1 <= n) {
                    dp[i][j] += dp[i][j + 1];
                }
                //cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
            }
        }
    }
    return dp[0][0];
}

void solve() {
    int n, l, r;
    cin >> n >> l >> r;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    //cout << dps(n, a, b, l-1);
    cout << dps(n, a, b, r) - dps(n, a, b, l-1) << '\n';
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}

/*
2 2 50
3 4 0 1 1 0 1 1
4 5 1 2 1 1 1 2
 */

提出情報

提出日時
問題 A - Use Udon Coupon
ユーザ SomethingNew
言語 C++ 20 (gcc 12.2)
得点 700
コード長 4755 Byte
結果 AC
実行時間 235 ms
メモリ 199012 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 700 / 700
結果
AC × 3
AC × 33
セット名 テストケース
Sample 01-sample-01.txt, 01-sample-02.txt, 01-sample-03.txt
All 01-sample-01.txt, 01-sample-02.txt, 01-sample-03.txt, 02-large-random-01.txt, 02-large-random-02.txt, 02-large-random-03.txt, 02-large-random-04.txt, 02-large-random-05.txt, 02-large-random-06.txt, 02-large-random-07.txt, 02-large-random-08.txt, 02-large-random-09.txt, 02-large-random-10.txt, 03-small-random-01.txt, 03-small-random-02.txt, 03-small-random-03.txt, 03-small-random-04.txt, 03-small-random-05.txt, 03-small-random-06.txt, 03-small-random-07.txt, 03-small-random-08.txt, 03-small-random-09.txt, 03-small-random-10.txt, 04-large-random-2-01.txt, 04-large-random-2-02.txt, 04-large-random-2-03.txt, 04-large-random-2-04.txt, 04-large-random-2-05.txt, 05-large-random-small-range-01.txt, 05-large-random-small-range-02.txt, 05-large-random-small-range-03.txt, 05-large-random-small-range-04.txt, 05-large-random-small-range-05.txt
ケース名 結果 実行時間 メモリ
01-sample-01.txt AC 1 ms 3444 KiB
01-sample-02.txt AC 1 ms 3332 KiB
01-sample-03.txt AC 1 ms 3468 KiB
02-large-random-01.txt AC 235 ms 199012 KiB
02-large-random-02.txt AC 211 ms 196092 KiB
02-large-random-03.txt AC 220 ms 189564 KiB
02-large-random-04.txt AC 200 ms 184180 KiB
02-large-random-05.txt AC 191 ms 185072 KiB
02-large-random-06.txt AC 210 ms 183624 KiB
02-large-random-07.txt AC 191 ms 193356 KiB
02-large-random-08.txt AC 220 ms 187044 KiB
02-large-random-09.txt AC 184 ms 183296 KiB
02-large-random-10.txt AC 209 ms 183100 KiB
03-small-random-01.txt AC 1 ms 3468 KiB
03-small-random-02.txt AC 1 ms 3492 KiB
03-small-random-03.txt AC 1 ms 3556 KiB
03-small-random-04.txt AC 1 ms 3440 KiB
03-small-random-05.txt AC 1 ms 3488 KiB
03-small-random-06.txt AC 1 ms 3624 KiB
03-small-random-07.txt AC 1 ms 3628 KiB
03-small-random-08.txt AC 1 ms 3404 KiB
03-small-random-09.txt AC 1 ms 3436 KiB
03-small-random-10.txt AC 1 ms 3484 KiB
04-large-random-2-01.txt AC 228 ms 198896 KiB
04-large-random-2-02.txt AC 221 ms 192396 KiB
04-large-random-2-03.txt AC 228 ms 196060 KiB
04-large-random-2-04.txt AC 201 ms 188452 KiB
04-large-random-2-05.txt AC 195 ms 188296 KiB
05-large-random-small-range-01.txt AC 199 ms 198996 KiB
05-large-random-small-range-02.txt AC 220 ms 189772 KiB
05-large-random-small-range-03.txt AC 221 ms 189940 KiB
05-large-random-small-range-04.txt AC 199 ms 183896 KiB
05-large-random-small-range-05.txt AC 199 ms 180224 KiB