Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2024
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. // Source: https://usaco.guide/general/io
  2.  
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5. #define MAXN 500010
  6. #define MOD 1000000007
  7. typedef long long ll;
  8. typedef pair<ll, ll> pi;
  9.  
  10. int main() {
  11. ios_base::sync_with_stdio(false);
  12. cin.tie(NULL);
  13. int tt; tt = 1;
  14. while (tt--) {
  15. int n; cin >> n;
  16. vector<int> a(n+1);
  17. for (int i = 1; i <= n; i++) cin >> a[i];
  18. ll idx = 2000;
  19. vector<ll> dp[n+1], cnt[n+1];
  20. vector<int> last(25, 0);
  21. dp[0].resize(idx+10, 0);
  22. cnt[0].resize(idx+10, 0);
  23. dp[0][1000] = 1;
  24. for (int i = 1; i <= n; i++) {
  25. dp[i].resize(idx+10, 0);
  26. cnt[i].resize(idx+10, 0);
  27. for (int j = 0; j <= idx; j++) dp[i][j] = dp[i-1][j];
  28. for (int j = 0; j <= idx; j++) cnt[i][j] = cnt[i-1][j];
  29. for (int j = 10; j <= idx-10; j++) {
  30. if (j == 1000) {
  31. if (last[a[i] + 10] == 0) cnt[i][j + a[i]] = (cnt[i][j + a[i]] % MOD + dp[i-1][j] % MOD) % MOD;
  32. else cnt[i][j + a[i]] = ((cnt[i][j + a[i]] + dp[i-1][j] - dp[last[a[i] + 10]-1][j]) + MOD) % MOD;
  33. } else dp[i][j + a[i]] = ((dp[i][j + a[i]] + dp[i-1][j]) % MOD + cnt[i-1][j]) % MOD;
  34. }
  35. last[a[i] + 10] = i;
  36. }
  37. ll ans = 0;
  38. for (int i = 0; i <= idx; i++) ans = (ans + dp[n][i]) % MOD;
  39. cout << ans << "\n";
  40. }
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement