QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#136287 | #5039. Black and White | PetroTarnavskyi# | WA | 11ms | 11348kb | C++17 | 2.5kb | 2023-08-07 19:05:04 | 2023-08-07 19:05:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int mod = 998244353;
int add(int a, int b){
return (a + b < mod) ? (a + b) : (a + b - mod);
}
int mult(int a, int b){
return 1LL * a * b % 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;
}
const int N = 1000'000;
int fact[N], ober[N];
/*
map<int, int> dp[N][N];
int F(int n, int m, int k)
{
if (dp[n][m].count(k)) return dp[n][m][k];
//if (n == 0 && m == 0) return (k == 0); // ?
if(n == 0) return (k == 0);
dp[n][m][k] = 0;
FOR(sz, 0, m + 1){
int nk = k;
if(sz % 2){
if(n % 2)
nk--;
else
nk++;
}
dp[n][m][k] += F(n - 1, sz, nk);
}
return dp[n][m][k];
}
*/
int C(int n, int k){
if(k < 0 || k > n)
return 0;
return mult(fact[n], mult(ober[k], ober[n - k]));
}
void prec(){
fact[0] = 1;
FOR(i, 1, N)
fact[i] = mult(fact[i - 1], i);
ober[N - 1] = binpow(fact[N - 1], mod - 2);
RFOR(i, N, 1)
ober[i - 1] = mult(ober[i], i);
}
int solve(int n, int m, int k){
int l = -(min(n, m) / 2);
int r = ((min(n, m) + 1) / 2);
return mult(C((n + m) / 2, k - l), C((n + m + 1) / 2, r - k));
}
void fin(int val, int n, int m){
FOR(i, 0, 20){
FOR(j, 0, 20){
int n0 = (n + m) / 2;
int m0 = (n + m + 1) / 2;
if(mult(C(n0, i), C(m0, j)) == val){
cout << n0 << " " << i << " " << m0 << " " << j << " " << val << endl;
return;
}
}
}
cerr << "bad" << endl;
cerr << n << " " << m << " " << val << endl;
exit(0);
assert(0);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
prec();
int t;
cin >> t;
while(t--){
int n, m, k;
cin >> n >> m >> k;
cout << solve(n, m, k) << "\n";
}
/* int mn = 10, mx = -10;
FOR (k, -5, 6)
{
F(n, m, k);
if(dp[n][m][k] != 0){
mn = min(mn, k);
mx = max(mx, k);
}
cout << k << ' ' << dp[n][m][k] << " " << solve(n, m, k) << '\n';
assert(dp[n][m][k] == solve(n, m, k));
fin(dp[n][m][k], n, m);
}
cerr << mn << " " << mx << endl;
*/
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 11ms
memory: 11272kb
input:
5 1 1 0 1 1 -1 2 2 1 2 2 0 4 4 1
output:
1 0 1 4 16
result:
ok 5 number(s): "1 0 1 4 16"
Test #2:
score: 0
Accepted
time: 11ms
memory: 11240kb
input:
100 1 1 -10 1 1 -9 1 1 -8 1 1 -7 1 1 -6 1 1 -5 1 1 -4 1 1 -3 1 1 -2 1 1 -1 1 1 0 1 1 1 1 1 2 1 1 3 1 1 4 1 1 5 1 1 6 1 1 7 1 1 8 1 1 9 1 1 10 1 2 -10 1 2 -9 1 2 -8 1 2 -7 1 2 -6 1 2 -5 1 2 -4 1 2 -3 1 2 -2 1 2 -1 1 2 0 1 2 1 1 2 2 1 2 3 1 2 4 1 2 5 1 2 6 1 2 7 1 2 8 1 2 9 1 2 10 1 3 -10 1 3 -9 1 3 -...
output:
0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 3 0 0 0 0
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 11ms
memory: 11280kb
input:
100 1 5 6 1 5 7 1 5 8 1 5 9 1 5 10 1 6 -10 1 6 -9 1 6 -8 1 6 -7 1 6 -6 1 6 -5 1 6 -4 1 6 -3 1 6 -2 1 6 -1 1 6 0 1 6 1 1 6 2 1 6 3 1 6 4 1 6 5 1 6 6 1 6 7 1 6 8 1 6 9 1 6 10 1 7 -10 1 7 -9 1 7 -8 1 7 -7 1 7 -6 1 7 -5 1 7 -4 1 7 -3 1 7 -2 1 7 -1 1 7 0 1 7 1 1 7 2 1 7 3 1 7 4 1 7 5 1 7 6 1 7 7 1 7 8 1 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6
result:
ok 100 numbers
Test #4:
score: -100
Wrong Answer
time: 8ms
memory: 11348kb
input:
100 1 10 1 1 10 2 1 10 3 1 10 4 1 10 5 1 10 6 1 10 7 1 10 8 1 10 9 1 10 10 2 1 -10 2 1 -9 2 1 -8 2 1 -7 2 1 -6 2 1 -5 2 1 -4 2 1 -3 2 1 -2 2 1 -1 2 1 0 2 1 1 2 1 2 2 1 3 2 1 4 2 1 5 2 1 6 2 1 7 2 1 8 2 1 9 2 1 10 2 2 -10 2 2 -9 2 2 -8 2 2 -7 2 2 -6 2 2 -5 2 2 -4 2 2 -3 2 2 -2 2 2 -1 2 2 0 2 2 1 2 2 ...
output:
5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 4 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 6 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 9 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 20th numbers differ - expected: '1', found: '0'