fork download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <vector>
  6. #include <set>
  7. #include <map>
  8. #include <string>
  9. #include <queue>
  10. #include <stack>
  11. #include <algorithm>
  12. #define dibs reserve
  13. #define OVER9000 1234567890
  14. #define tisic 47
  15. #define soclose 10e-7
  16. #define M 1000000007
  17. #define add(x,y) {x =(x+y)%M; if(x < 0) x +=M;}
  18. // mylittlepony
  19. using namespace std;
  20.  
  21. int main() {
  22. int N;
  23. cin >> N;
  24. vector<int> V(N);
  25. for(int i =0; i < N; i++) cin >> V[i];
  26. if(V[0] > 0 || V[N-1] > 0) {
  27. cout << "0\n";
  28. return 0;}
  29. V[0] =V[N-1] =0;
  30.  
  31. vector<long long> W(tisic,0);
  32. W[0] =1;
  33. for(int i =0; i < N; i++) {
  34. if(2*i <= N) W.push_back(0);
  35. if(V[i] == -1) {
  36. int a =W[0], b =W[1];
  37. add(W[0],W[1]);
  38. for(int j =1; j <= W.size()-1; j++) {
  39. add(W[j],a+W[j+1]);
  40. a =b;
  41. b =W[j+1];}}
  42. else {
  43. if(V[i] > i) {cout << "0\n"; return 0;}
  44. add(W[V[i]],W[V[i]+1]);
  45. if(V[i] > 0) add(W[V[i]],W[V[i]-1]);
  46. for(int j =0; j <= W.size()-1; j++) if(j != V[i]) W[j] =0;}
  47. }
  48. cout << W[0] << endl;
  49. return 0;}
  50.  
  51. // look at my code
  52. // my code is amazing
Success #stdin #stdout 0s 3036KB
stdin
6
-1 -1 -1 2 -1 -1
stdout
3