fork download
  1. #include <vector>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. static const unsigned MODVAL = 1000000007;
  6. struct mint
  7. {
  8. unsigned val;
  9. mint():val(0){}
  10. mint(int x):val(x%MODVAL) {}
  11. mint(unsigned x):val(x%MODVAL) {}
  12. };
  13. mint& operator+=(mint& x, mint y) { return x = x.val+y.val; }
  14.  
  15. class AlienAndSetDiv1 { public:
  16. int getNumber(int N, int K)
  17. {
  18. memo.assign((1<<K)*(N+1)*(N+1), -1);
  19. vector<int> A, B;
  20. return rec(N, K, A, B, 0);
  21. }
  22.  
  23. vector<int> memo;
  24. int rec(size_t N, int K, vector<int>& A, vector<int>& B, int lastk)
  25. {
  26. if(A.size()==N && B.size()==N)
  27. return 1;
  28.  
  29. auto key = (lastk*(N+1)+A.size())*(N+1)+B.size();
  30. if(memo[key] >= 0)
  31. return memo[key];
  32.  
  33. int next = A.size()+B.size()+1, nextmask = (lastk &~ (1<<(K-1)))<<1;
  34. int ai = A.size(), bi = B.size();
  35.  
  36. mint total = 0;
  37.  
  38. A.push_back(next);
  39. if(A.size()<=N && (ai>=B.size() || abs(A[ai]-B[ai])>=K))
  40. total += rec(N, K, A, B, nextmask);
  41. A.pop_back();
  42. B.push_back(next);
  43. if(B.size()<=N && (bi>=A.size() || abs(A[bi]-B[bi])>=K))
  44. total += rec(N, K, A, B, nextmask|1);
  45. B.pop_back();
  46.  
  47. return memo[key] = total.val;
  48. }
  49. };
  50.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In member function ‘int AlienAndSetDiv1::rec(std::size_t, int, std::vector<int>&, std::vector<int>&, int)’:
prog.cpp:39:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(A.size()<=N && (ai>=B.size() || abs(A[ai]-B[ai])>=K))
                                 ^
prog.cpp:43:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(B.size()<=N && (bi>=A.size() || abs(A[bi]-B[bi])>=K))
                                 ^
/usr/lib/gcc/i486-linux-gnu/4.8/../../../i386-linux-gnu/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty