QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#313294 | #8142. Elevator | PetroTarnavskyi# | WA | 8ms | 11828kb | C++20 | 2.0kb | 2024-01-24 17:16:22 | 2024-01-24 17:16:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 1'000'000'007;
const int N = 1 << 20;
const int LOG = 52;
const int K = 19;
int fact[N], ifact[N];
int mult(int a, int b)
{
return (LL) a * b % mod;
}
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
int sub(int a, int b)
{
return a - b >= 0 ? a - b : a - b + mod;
}
void updAdd(int& a, int b)
{
a += b;
if (a >= mod)
a -= mod;
}
int binpow(int a, int n)
{
int res = 1;
while(n)
{
if(n & 1)
res = mult(res, a);
a = mult(a, a);
n /= 2;
}
return res;
}
void init()
{
fact[0] = 1;
FOR(i, 1, N)
fact[i] = mult(fact[i - 1], i);
ifact[N - 1] = binpow(fact[N - 1], mod - 2);
RFOR(i, N, 1)
ifact[i - 1] = mult(ifact[i], i);
}
int C(int n, int k)
{
return mult(fact[n], mult(ifact[n - k], ifact[k]));
}
int getBit(LL n, int i)
{
return (n >> i) & 1;
}
LL m;
int k;
unordered_map<LL, int> dp[LOG][K];
int f(int pos, int cnt, LL n)
{
if (n > (k / 2) * (k + 1) / 2 * ((1LL << pos) - 1))
return 0;
if (pos == 0)
return 1;
if (dp[pos][cnt].count(n))
return dp[pos][cnt][n];
int& res = dp[pos][cnt][n];
int b = getBit(m, pos - 1);
int v = b ? 1 : cnt;
FOR(i, 0, v + 1)
{
FOR(j, 0, k - cnt + 1)
{
LL nn = n - (((LL)(i + j) * (k - i - j)) << (pos - 1));
if (nn >= 0)
updAdd(res, mult(mult(C(cnt, i), C(k - cnt, j)), dp[pos - 1][b ? i : cnt][nn]));
}
}
cerr << pos << " " << cnt << " " << n << endl;
return res;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
init();
LL n;
cin >> n >> m >> k;
cout << f(LOG - 1, k, n) << "\n";
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 11828kb
input:
6 20 3 8 12 6 9 9
output:
0
result:
wrong answer 2nd lines differ - expected: '8', found: ''