# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72442 | (#118) | Dstorv (FXCUP3_dstorv) | C++17 | 34 ms | 30436 KiB |
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 <cstdio>
#include <cassert>
using namespace std;
const int MOD = 1000000007;
char s[5002];
int upper[5002];
int dp[5002][5002]; // a개의 손을 없앴을 때 b개의 꽃이 죽음
int inv(int x){
int v = 1, w = x, z = MOD - 2;
while(z > 0){
if(z & 1) v = 1LL * v * w % MOD;
w = 1LL * w * w % MOD;
z >>= 1;
}
return v;
}
int main(){
int N, R, H; scanf("%d%d%d", &N, &R, &H);
scanf("%s", s + 1);
int A, B; scanf("%d%d", &A, &B);
int hc = 0, rc = 0;
for(int i = 1; i <= N; i++){
if(s[i] == 'R') rc++;
else upper[++hc] = rc;
}
// printf("rc : %d, hc : %d\n", rc, hc);
if(A > rc || B > hc){ puts("0"); return 0; }
if(B != 0) assert(false);
int res = 1, den = inv(R + H);
for(int i = 1; i <= rc - A; i++) res = 1LL * res * R % MOD;
for(int i = 1; i <= hc; i++) res = 1LL * res * H % MOD;
for(int i = 1; i <= rc - A + hc; i++) res = 1LL * res * den % MOD;
// printf("%d\n", res);
dp[0][0] = 1;
for(int i = 1; i <= hc; i++){
int s = 0;
// printf("upper : %d\n", upper[i]);
for(int j = 0; j < upper[i]; j++){
s += dp[i - 1][j]; if(s >= MOD) s -= MOD;
dp[i][j] = s;
}
}
int cnt = dp[hc][rc - A];
printf("%lld\n", 1LL * res * cnt % MOD);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |