Submission #40652643
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define fastio cin.tie(0)->sync_with_stdio(0)
#define fi first
#define se second
#define nm (nl + nr >> 1)
#define xm (xl + xr >> 1)
#define pb(x) push_back(x)
#define all(v) (v).begin(), (v).end()
#define zip(v) (v).erase(unique(all(v)), (v).end())
#define dem_plc(x) cout << fixed << setprecision(x)
#define ox(t) cout << ((t) ? "Yes" : "No") << '\n'
#define continue(x) { cout << (x) << '\n'; continue; }
#define _exit(x) return cout << x, 0
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<pii, int> ppi;
typedef pair<int, pii> pip;
typedef pair<pll, ll> ppl;
typedef pair<ll, pll> plp;
const ll mod = 998244353;
const ll INF = 2e9;
const ll LINF = 4e18;
const db PI = acos(-1);
const int N = 101;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
// templete end
ll _pow(ll x, ll y) {
ll ret = 1;
for(; y; x = x * x % mod, y >>= 1) if(y & 1) ret = ret * x % mod;
return ret;
}
int n, p, q;
ll P, Q, dp[N][N], pd[N][N];
ll g(int a, int b);
ll f(int a, int b) {
if(a >= n) return 1;
if(b >= n) return 0;
ll &ret = dp[a][b];
if(ret >= 0) return ret;
ll sum = 0;
for(int i = 1; i <= p; i++) sum = (sum + g(a + i, b)) % mod;
return ret = sum * P % mod;
}
ll g(int a, int b) {
if(a >= n) return 1;
if(b >= n) return 0;
ll &ret = pd[a][b];
if(ret >= 0) return ret;
ll sum = 0;
for(int i = 1; i <= q; i++) sum = (sum + f(a, b + i)) % mod;
return ret = sum * Q % mod;
}
int main()
{
fastio;
memset(dp, -1, sizeof dp);
memset(pd, -1, sizeof pd);
int a, b; cin >> n >> a >> b >> p >> q;
P = _pow(p, mod - 2), Q = _pow(q, mod - 2);
cout << f(a, b) << '\n';
}
Submission Info
Submission Time |
|
Task |
E - Unfair Sugoroku |
User |
HeeJaYaa |
Language |
C++ (GCC 9.2.1) |
Score |
500 |
Code Size |
1933 Byte |
Status |
AC |
Exec Time |
8 ms |
Memory |
3748 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample00.txt, sample01.txt, sample02.txt |
All |
sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt |
Case Name |
Status |
Exec Time |
Memory |
sample00.txt |
AC |
8 ms |
3740 KiB |
sample01.txt |
AC |
3 ms |
3740 KiB |
sample02.txt |
AC |
5 ms |
3584 KiB |
testcase00.txt |
AC |
4 ms |
3680 KiB |
testcase01.txt |
AC |
2 ms |
3688 KiB |
testcase02.txt |
AC |
2 ms |
3708 KiB |
testcase03.txt |
AC |
2 ms |
3700 KiB |
testcase04.txt |
AC |
3 ms |
3640 KiB |
testcase05.txt |
AC |
2 ms |
3696 KiB |
testcase06.txt |
AC |
2 ms |
3692 KiB |
testcase07.txt |
AC |
2 ms |
3688 KiB |
testcase08.txt |
AC |
2 ms |
3688 KiB |
testcase09.txt |
AC |
2 ms |
3700 KiB |
testcase10.txt |
AC |
2 ms |
3712 KiB |
testcase11.txt |
AC |
2 ms |
3704 KiB |
testcase12.txt |
AC |
4 ms |
3644 KiB |
testcase13.txt |
AC |
2 ms |
3628 KiB |
testcase14.txt |
AC |
6 ms |
3712 KiB |
testcase15.txt |
AC |
4 ms |
3704 KiB |
testcase16.txt |
AC |
4 ms |
3716 KiB |
testcase17.txt |
AC |
3 ms |
3636 KiB |
testcase18.txt |
AC |
2 ms |
3640 KiB |
testcase19.txt |
AC |
3 ms |
3640 KiB |
testcase20.txt |
AC |
3 ms |
3684 KiB |
testcase21.txt |
AC |
5 ms |
3688 KiB |
testcase22.txt |
AC |
3 ms |
3748 KiB |
testcase23.txt |
AC |
3 ms |
3696 KiB |
testcase24.txt |
AC |
5 ms |
3696 KiB |
testcase25.txt |
AC |
5 ms |
3704 KiB |