Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- #define int unsigned long long
- const int N = 50;
- int MD, OD;
- int row, col;
- int cnt = 0, n;
- inline bool val(int r, int c) {
- if (MD & (1LL<<(r+c))) return 0;
- if (OD & (1LL<<(r-c+n-1))) return 0;
- if (row & (1LL<<r)) return 0;
- if (col & (1LL<<c)) return 0;
- return 1;
- }
- inline void Set(int r, int c) {
- row |= (1LL<<r);
- col |= (1LL<<c);
- MD |= (1LL<<(r+c));
- OD |= (1LL<<(r-c+n-1));
- }
- inline void reset(int r, int c) {
- row -= (1LL<<r);
- col -= (1LL<<c);
- MD -= (1LL<<(r+c));
- OD -= (1LL<<(r-c+n-1));
- }
- int ans = 0;
- void go(int curCol) {
- ++cnt;
- if (curCol == n) {
- cout << "Found\n";
- ++ans;
- exit(0);
- return;
- }
- for (int r = 0; r < n; ++r) {
- if (val(r, curCol)) {
- Set(r, curCol);
- go(curCol+1);
- reset(r, curCol);
- }
- }
- }
- signed main() {
- n = 30;
- cin >> n;
- go(0);
- cout << ans;
- }
Add Comment
Please, Sign In to add comment