fork download
  1. #include <cstdio>
  2.  
  3. constexpr const int a[] = {1, -2, 2, -2, 5, -2, 7, 8, 9, 1};
  4. constexpr const unsigned n = sizeof a / sizeof *a;
  5.  
  6. template <const int *x, unsigned i=0, long long t=1> class c
  7. {
  8. public:
  9. const static long long p = c<x, i+1, x[i]<0 ? t**(x+i) : t>::p;
  10. const static long long s = c<x, i+1, (x[i]>0) ? t+x[i] : t>::s;
  11. };
  12.  
  13. template <const int *x, long long t> class c<x, n, t>
  14. {
  15. public:
  16. const static long long p = t;
  17. const static long long s = t-1;
  18. };
  19.  
  20. constexpr long long p()
  21. {
  22. return c<a>::p;
  23. }
  24.  
  25. constexpr long long s()
  26. {
  27. return c<a>::s;
  28. }
  29.  
  30. int main(void)
  31. {
  32. return !printf("%Ld\n%Ld\n", p(), s());
  33. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
-8
33