This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 10;
vector<int> v;
int grupo[MAXN];
int resp = 0;
int modulo = 1e9 + 7;
int fat(int x)
{
if (x == 0) return 1;
if (x == 1) return 1;
cerr << "E" << '\n';
return ((x * fat(x-1)) % modulo);
}
void bt(int id, int N, int M)
{
cerr << "Inicio de " << id << '\n';
if (id == N+1)
{
int aux = 1;
for (int i = 1; i <= M; i++)
{
if (grupo[i] > ((2*N) / M) + ((2*N) % M >= i)) {cerr << "fim de " << id << '\n';return;}
aux *= fat(grupo[i]);
aux = aux % modulo;
cerr << aux << '\n';
}
resp += aux;
resp = resp % modulo;
cerr << "resp: " << resp << '\n';
cerr << "Fim de " << id << '\n';
return;
}
for (int i = 1; i <= M; i++)
{
for (int j = 1; j <= M; j++)
{
if (i == j) continue;
if (grupo[i] >= ((2*N) / M) + ((2*N) % M >= i)) continue;
if (grupo[j] >= ((2*N) / M) + ((2*N) % M >= j)) continue;
grupo[i]++; grupo[j]++;
bt(id+1, N, M);
grupo[i]--; grupo[j]--;
}
}
cerr << "Fim de " << id << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N >> M;
if ((2*N / M) + ((2*N) % M > 0) > N)
{
cout << "0";
return 0;
}
bt(1, N, M);
cout << resp;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |