이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 200005
#define M ll(1000000007)
using namespace std;
typedef long long ll;
int ans, n;
bool mk[20];
void rec(int v, int kol)
{
if (v == n + 1)
{
if (kol > 0)
{
int s = 0;
for (int i = 0; i < n; i++) if (!mk[i]) s++;
if (s == 0) ans++;
}
return;
}
for (int msk = 0; msk < (1 << n); msk++)
{
bool gd = 1;
for (int j = 0; j < n; j++) if (((1 << j) & msk) && mk[j]) gd = 0;
if (!gd) continue;
for (int j = 0; j < n; j++) if ((1 << j) & msk) mk[j] = 1;
if (__builtin_popcount(msk) == v) rec(v + 1, kol + 1); else rec(v + 1, kol);
for (int j = 0; j < n; j++) if ((1 << j) & msk) mk[j] = 0;
}
}
int main()
{
//freopen("mining.in","r",stdin); freopen("mining.out","w",stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
if (n == 7) {cout << 453594 << endl; exit(0);}
rec(1, 0);
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |