Submission #55020237


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define mp make_pair
#define all(x) x.begin(), x.end()
#define x first
#define y second

const int mod = 1e9 + 7;


void solve() {

    int n;
    cin >> n;
    vector<int> A(n);
    for (auto& i : A) cin >> i;

    vector<ll> dp(2020), init(2020);
    int b = 1000;
    init[b] = 1;
    for (int i = 0; i < n; i++) {
        ll v = A[i];
        if (v > 0) {
            for (int j = b * 2; j >= v; j--) {
                if (j == b + v) {
                    init[j] = dp[b] + 1;
                    //(dp[j] += dp[j - v]) %= mod;
                }
                else (dp[j] += dp[j - v] + init[j-v]) %= mod;
            }
        }
        else if (v < 0) {
            for (int j = 0; j - v <= b * 2 ; j++) {
                if (j == b + v) {
                    init[j] = dp[b] + 1;
                   // (dp[j] += dp[j - v]) %= mod;
                }
                else (dp[j] += dp[j - v] + init[j-v]) %= mod;
            }
        }
        else {
            for (int j = 0; j <= b * 2; j++) {
                if (j == b) {}
                else (dp[j] += dp[j + v] + init[j+v]) %= mod;
            }
        }
    }
    ll ans = 0;
    for (auto f : dp) ans = (ans + f) % mod;
    cout << (ans + 1) % mod << '\n';
}

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

Submission Info

Submission Time
Task C - Subsequence and Prefix Sum
User JYJin
Language C++ 20 (gcc 12.2)
Score 600
Code Size 1478 Byte
Status AC
Exec Time 1 ms
Memory 3640 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 4
AC × 30
Set Name Test Cases
Sample 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 00-sample-004.txt
All 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 00-sample-004.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 1 ms 3508 KiB
00-sample-002.txt AC 1 ms 3476 KiB
00-sample-003.txt AC 1 ms 3444 KiB
00-sample-004.txt AC 1 ms 3496 KiB
01-001.txt AC 1 ms 3500 KiB
01-002.txt AC 1 ms 3496 KiB
01-003.txt AC 1 ms 3436 KiB
01-004.txt AC 1 ms 3352 KiB
01-005.txt AC 1 ms 3544 KiB
01-006.txt AC 1 ms 3404 KiB
01-007.txt AC 1 ms 3632 KiB
01-008.txt AC 1 ms 3456 KiB
01-009.txt AC 1 ms 3500 KiB
01-010.txt AC 1 ms 3500 KiB
01-011.txt AC 1 ms 3420 KiB
01-012.txt AC 1 ms 3548 KiB
01-013.txt AC 1 ms 3504 KiB
01-014.txt AC 1 ms 3344 KiB
01-015.txt AC 1 ms 3540 KiB
01-016.txt AC 1 ms 3536 KiB
01-017.txt AC 1 ms 3444 KiB
01-018.txt AC 1 ms 3428 KiB
01-019.txt AC 1 ms 3404 KiB
01-020.txt AC 1 ms 3640 KiB
01-021.txt AC 1 ms 3452 KiB
01-022.txt AC 1 ms 3440 KiB
01-023.txt AC 1 ms 3436 KiB
01-024.txt AC 1 ms 3440 KiB
01-025.txt AC 1 ms 3460 KiB
01-026.txt AC 1 ms 3500 KiB