fork download
  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <cmath>
  5. #include <algorithm>
  6. #include <fstream>
  7. #include<stdlib.h>
  8.  
  9. #define rep( i, l, r ) for (int i = l; i <= r; i++)
  10. #define down( i, l, r ) for (int i = l; i >= r; i--)
  11.  
  12. using namespace std;
  13.  
  14. int n, num[10009], ans, now[10009];
  15.  
  16. void Seache(int w)
  17. {
  18. if (w == 1)
  19. {
  20. if (num[1] == 2)
  21. {
  22. now[1] = now[2] = 1; Seache(2);
  23. }
  24. else if (num[1] == 0)
  25. {
  26. now[1] = now[2] = 0; Seache(2);
  27. }
  28. else
  29. {
  30. now[1] = 1; now[2] = 0; Seache(2);
  31. now[1] = 0; now[2] = 1; Seache(2);
  32. }
  33. }
  34. else if (w == n)
  35. {
  36. if (num[w] == now[w-1] + now[w]) ans++;
  37. }
  38. else
  39. {
  40. int a = num[w] - now[w-1] - now[w];
  41. if (a == 0)
  42. {
  43. now[w+1] = 0; Seache(w+1);
  44. }
  45. else if (a == 1)
  46. {
  47. now[w+1] = 1; Seache(w+1);
  48. }
  49. }
  50. }
  51.  
  52. int main()
  53. {
  54. scanf("%d", &n);
  55. rep(i, 1, n) scanf("%d", &num[i]);
  56. ans = 0;
  57. rep(i, 1, n) if (num[i] > 3 || num[i] < 0) ans = -1;
  58. if (num[1] > 2 || num[n] > 2) ans = -1;
  59. rep(i, 2, n) if (num[i-1] - num[i] < -1 || num[i-1] - num[i] > 1) ans = -1;
  60. if (ans != -1) Seache(1); else ans = 0;
  61. printf("%d", ans);
  62. return 0;
  63. }
  64.  
Success #stdin #stdout 0s 3376KB
stdin
2
1 1
stdout
2