fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4.  
  5. int n;
  6. int solution_count = 0;
  7. uint32_t col=0, asc=0, desc=0;
  8.  
  9. void backtrack(int i)
  10. {
  11. if(i == n) {
  12. solution_count++;
  13. return;
  14. }
  15. uint32_t mc, md, ma;
  16. for(int j=0; j != n; j++) {
  17. if (col & (mc = 1<<j)) continue;
  18. if (desc & (md = 1 << (i+j))) continue;
  19. if (asc & (ma = 1 << (15+i-j))) continue;
  20. uint32_t oldc = col, oldd = desc, olda = asc;
  21. col |= mc;
  22. desc |= md;
  23. asc |= ma;
  24. backtrack(i+1);
  25. col = oldc;
  26. desc = oldd;
  27. asc = olda;
  28. }
  29. }
  30.  
  31. int main()
  32. {
  33. n = 14;
  34. backtrack(0);
  35. printf("%d", solution_count);
  36. return 0;
  37. }
Success #stdin #stdout 4.04s 2156KB
stdin
Standard input is empty
stdout
365596