fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long int
  4. #define double long double
  5. #define print(a) for(auto x : a) cout << x << " "; cout << endl
  6.  
  7.  
  8. const int M = 1000000007;
  9. const int N = 3e5+9;
  10. const int INF = 2e9+1;
  11. const int LINF = 2000000000000000001;
  12.  
  13. inline int power(int a, int b, int mod=M) {
  14. int x = 1;
  15. a %= mod;
  16. while (b) {
  17. if (b & 1) x = (x * a) % mod;
  18. a = (a * a) % mod;
  19. b >>= 1;
  20. }
  21. return x;
  22. }
  23.  
  24.  
  25. //_ ***************************** START Below *******************************
  26.  
  27.  
  28.  
  29.  
  30. vector<int> a;
  31.  
  32. int consistency1(int n){
  33. if(n==1 && a[0] < 0) return 1;
  34.  
  35.  
  36. vector<int> dp(n+1, 0);
  37. dp[0] = 1;
  38. if(a[0] < 0) dp[1] = 1;
  39.  
  40. for(int i=2; i<=n; i++){
  41.  
  42. int j = i-1;
  43. int negCt = a[i-1]<0 ? 1 : 0;
  44.  
  45. while(j>=0){
  46.  
  47. if(negCt >= 1){
  48. dp[i] += dp[j];
  49. }
  50.  
  51. if(j-1>=0){
  52. if(a[j-1] < 0) negCt++;
  53. }
  54. j--;
  55. }
  56. }
  57.  
  58. return dp[n];
  59.  
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. int consistency2(int n){
  68. if(n==1 && a[0] < 0) return 1;
  69.  
  70. int lastNeg = -1;
  71.  
  72. vector<int> dp(n+1, 0);
  73. vector<int> prefixDp(n+1, 0);
  74.  
  75. dp[0] = 1;
  76. prefixDp[0] = 1;
  77.  
  78. if(a[0] < 0){
  79. dp[1] = 1;
  80. lastNeg = 0;
  81. }
  82. prefixDp[1] = dp[0] + dp[1];
  83.  
  84.  
  85. for(int i=2; i<=n; i++){
  86.  
  87. if(a[i-1]<0) lastNeg = i-1;
  88.  
  89. if(lastNeg != -1) dp[i] = prefixDp[lastNeg];
  90.  
  91. prefixDp[i] = prefixDp[i-1] + dp[i];
  92.  
  93. }
  94.  
  95. return dp[n];
  96.  
  97. }
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. int practice(int n){
  120.  
  121.  
  122. return 0;
  123. }
  124.  
  125.  
  126.  
  127.  
  128.  
  129. void solve() {
  130.  
  131. int n;
  132. cin>> n;
  133.  
  134. a.resize(n);
  135. for(int i=0; i<n; i++) cin >> a[i];
  136.  
  137. cout << consistency1(n) << " " << consistency2(n) << endl;
  138.  
  139. // cout << consistency1(n) << endl;
  140.  
  141.  
  142. }
  143.  
  144.  
  145.  
  146.  
  147.  
  148. int32_t main() {
  149. ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  150.  
  151. int t = 1;
  152. // cin >> t;
  153. while (t--) {
  154. solve();
  155. }
  156.  
  157. return 0;
  158. }
Success #stdin #stdout 0s 5312KB
stdin
8
2 -3 4 5 -10 6 -8 10
stdout
12 12