Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Source: https://usaco.guide/general/io
- #include <bits/stdc++.h>
- using namespace std;
- #define MAXN 500010
- #define MOD 1000000007
- typedef long long ll;
- typedef pair<ll, ll> pi;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- int tt; tt = 1;
- while (tt--) {
- int n; cin >> n;
- vector<int> a(n+1);
- for (int i = 1; i <= n; i++) cin >> a[i];
- ll idx = 2000;
- vector<ll> dp[n+1], cnt[n+1];
- vector<int> last(25, 0);
- dp[0].resize(idx+10, 0);
- cnt[0].resize(idx+10, 0);
- dp[0][1000] = 1;
- for (int i = 1; i <= n; i++) {
- dp[i].resize(idx+10, 0);
- cnt[i].resize(idx+10, 0);
- for (int j = 0; j <= idx; j++) dp[i][j] = dp[i-1][j];
- for (int j = 0; j <= idx; j++) cnt[i][j] = cnt[i-1][j];
- for (int j = 10; j <= idx-10; j++) {
- if (j == 1000) {
- if (last[a[i] + 10] == 0) cnt[i][j + a[i]] = (cnt[i][j + a[i]] % MOD + dp[i-1][j] % MOD) % MOD;
- else cnt[i][j + a[i]] = ((cnt[i][j + a[i]] + dp[i-1][j] - dp[last[a[i] + 10]-1][j]) + MOD) % MOD;
- } else dp[i][j + a[i]] = ((dp[i][j + a[i]] + dp[i-1][j]) % MOD + cnt[i-1][j]) % MOD;
- }
- last[a[i] + 10] = i;
- }
- ll ans = 0;
- for (int i = 0; i <= idx; i++) ans = (ans + dp[n][i]) % MOD;
- cout << ans << "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement