답안 #72442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72442 2018-08-26T08:11:11 Z (#2175, xdoju, kazel, pps789) 디스토브 (FXCUP3_dstorv) C++17
29 / 100
34 ms 30436 KB
#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

dstorv.cpp: In function 'int main()':
dstorv.cpp:26:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int N, R, H; scanf("%d%d%d", &N, &R, &H);
                ~~~~~^~~~~~~~~~~~~~~~~~~~~~
dstorv.cpp:28:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s + 1);
   ~~~~~^~~~~~~~~~~~~
dstorv.cpp:30:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int A, B; scanf("%d%d", &A, &B);
             ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Runtime error 5 ms 560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 712 KB Output is correct
2 Correct 6 ms 3660 KB Output is correct
3 Correct 16 ms 12912 KB Output is correct
4 Correct 28 ms 23008 KB Output is correct
5 Correct 34 ms 30436 KB Output is correct
6 Correct 3 ms 30436 KB Output is correct
7 Correct 2 ms 30436 KB Output is correct
8 Correct 3 ms 30436 KB Output is correct
9 Correct 27 ms 30436 KB Output is correct
10 Correct 26 ms 30436 KB Output is correct
11 Correct 25 ms 30436 KB Output is correct
12 Correct 25 ms 30436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 356 KB Output is correct
3 Runtime error 5 ms 560 KB Execution killed with signal 11 (could be triggered by violating memory limits)
4 Halted 0 ms 0 KB -