fork(9) download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int queens (){
  6. int pos[] = {0,1,2,3,4,5,6,7},ans = 0;
  7. while(next_permutation(pos,pos+8)){
  8. bool ok = true;
  9. for(int* p = pos;p<pos+8;p++)
  10. if ( count_if(pos,p,[=](int& j){return p - &j == *p-j || p - &j == j - *p ;}) )
  11. ok = false;
  12. ans += ok;
  13. }
  14. return ans;
  15. }
  16. int main() {
  17. cout<<queens();
  18. return 0;
  19. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
92