QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#851959 | #9995. 乒乓球赛 | JEdward | WA | 19ms | 5768kb | C++20 | 3.6kb | 2025-01-11 09:28:19 | 2025-01-11 09:28:19 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
#define endl '\n'
#define lowbit(x) (x & -x)
#define all(s) s.begin(), s.end()
#define pii pair<int, int>
#define ls(x) (x << 1)
#define rs(x) (x << 1 | 1)
#define here system("pause")
using namespace std;
template <class T>
inline void read(T &x)
{
x = 0;
char c = getchar();
bool f = 0;
for (; !isdigit(c); c = getchar())
f ^= (c == '-');
for (; isdigit(c); c = getchar())
x = (x << 3) + (x << 1) + (c ^ 48);
x = f ? -x : x;
}
template <class T>
inline void write(T x)
{
if (x < 0)
putchar('-'), x = -x;
if (x < 10)
putchar(x + 48);
else
write(x / 10), putchar(x % 10 + 48);
}
template <typename T>
void chkmin(T &lhs, const T &rhs) { lhs = lhs > rhs ? rhs : lhs; }
template <typename T>
void chkmax(T &lhs, const T &rhs) { lhs = lhs < rhs ? rhs : lhs; }
const int N = 2e5 + 5;
const int mod = 998244353;
const int INF = 8e18 + 9;
const double eps = 1e-9;
const double Pi = acos(-1);
inline int pow(int a, int b, int p)
{
int res = 1 % p;
while (b)
{
if (b & 1)
res = res * a % p;
a = a * a % p, b >>= 1;
}
return res;
}
inline int inv(int a, int p) { return pow(a, p - 2, p) % p; }
mt19937 rnd(chrono::duration_cast<chrono::nanoseconds>(chrono::system_clock::now().time_since_epoch()).count());
int randint(int L, int R)
{
uniform_int_distribution<int> dist(L, R);
return dist(rnd);
}
int n;
int a[N], b[N];
int dp[25][25]; // dp[i][j] 表示前 i 个轮,甲的得分为 j 的方案数
inline void sol()
{
cin >> n;
for (int i = 0; i <= min(n + 1, 21LL); i++)
{
for (int j = 0; j <= 20; j++)
{
dp[i][j] = 0;
}
}
for (int i = 1; i <= n; i++)
{
cin >> a[i] >> b[i];
if (a[i] < b[i])
swap(a[i], b[i]); // a[i] is bigger
}
for (int i = 1; i <= n; i++)
{
if (a[i] != -1)
{
if (a[i] + b[i] != i)
return cout << 0 << endl, void();
if (a[i] >= 11 && a[i] - b[i] >= 2 && i != n)
return cout << 0 << endl, void();
}
}
if (n < 11)
return cout << 0 << endl, void();
if (n > 20 && (n % 2 == 1))
return cout << 0 << endl, void();
if (a[n] != -1 && (a[n] < 11 || a[n] - b[n] < 2))
return cout << 0 << endl, void();
dp[0][0] = 1;
for (int i = 1; i <= min(n, 20LL); i++)
{
if (a[i] == -1)
{
for (int j = 0; j <= i; j++)
{
if (j == 0)
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
else
dp[i][j] = (dp[i][j] + dp[i - 1][j] + dp[i - 1][j - 1]) % mod;
if (max(j, i - j) >= 11 && max(j, i - j) - min(j, i - j) >= 2 && i != n)
dp[i][j] = 0;
}
}
else
{
if (a[i] == 0)
dp[i][a[i]] = (dp[i][a[i]] + dp[i - 1][a[i]]) % mod;
else
dp[i][a[i]] = (dp[i][a[i]] + dp[i - 1][a[i]] + dp[i - 1][a[i] - 1]) % mod;
if (max(a[i], i - a[i]) >= 11 && max(a[i], i - a[i]) - min(a[i], i - a[i]) >= 2 && i != n)
dp[i][a[i]] = 0;
if (a[i] == b[i])
continue;
if (b[i] == 0)
dp[i][b[i]] = (dp[i][b[i]] + dp[i - 1][b[i]]) % mod;
else
dp[i][b[i]] = (dp[i][b[i]] + dp[i - 1][b[i]] + dp[i - 1][b[i] - 1]) % mod;
if (max(b[i], i - b[i]) >= 11 && max(b[i], i - b[i]) - min(b[i], i - b[i]) >= 2 && i != n)
dp[i][b[i]] = 0;
}
}
int ans = 0;
if (n > 20)
{
ans = dp[20][10];
for (int i = 22; i <= n; i += 2)
{
if (a[i] != b[i] && i != n)
return cout << 0 << endl, void();
ans = ans * 2 % mod;
}
}
else
{
ans = (dp[n][n - 11] + dp[n][11]) % mod;
}
cout << ans << endl;
}
signed main()
{
IOS;
int tc = 1;
cin >> tc;
while (tc--)
{
sol();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
input:
7 11 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 11 -1 -1 1 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 11 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 1 11 22 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...
output:
2 0 0 0 369512 0 864
result:
ok 7 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
12 10 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 11 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 12 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 12 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 11 0 -1 -1 12 -1 -1 -1 -1 -...
output:
0 2 22 0 0 0 0 369512 0 0 0 0
result:
ok 12 lines
Test #3:
score: -100
Wrong Answer
time: 19ms
memory: 5712kb
input:
20000 16 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 25 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 13 -1 -1 -1 -1 -1 -1 -1 -1 -...
output:
6006 0 0 132 0 0 2002 0 0 0 0 369512 184756 0 0 0 0 41756 572 0 2 2002 2 0 6006 0 0 38896 369512 87516 369512 0 6006 0 0 6006 0 369512 0 0 369512 572 184756 0 739024 87516 145860 2 0 16016 0 2002 6006 0 0 0 0 0 132 6006 572 2002 0 3520 0 0 0 0 22 0 2 184756 0 0 0 0 0 0 0 0 0 572 3432 572 132 3960 57...
result:
wrong answer 7122nd lines differ - expected: '0', found: '369512'