Submission #66545

# Submission time Handle Problem Language Result Execution time Memory
66545 2018-08-11T11:22:01 Z 검수컵(#1978, imsifile) Dstorv (FXCUP3_dstorv) C++
9 / 100
1000 ms 536 KB
#include<stdio.h>
#include<cstring>
#include<string>
using namespace std;

typedef long long lld;
const lld mod = 1000000007;

lld ex(lld a, lld b){
	lld gop=1;
	for(; b; b>>=1){
		if(b&1) gop=gop*a%mod;
		a=a*a%mod;
	}
	return gop;
}

lld r, h, rh, sum;
int N, A, B;
char st[5050];

void dfs(string s, int a, int b, lld prob){
	if(s==""){
		if(a==A && b==B) sum = (sum+prob)%mod;
		return;
	}
	int i; string rx="", hx="";
	for(i=0; i<s.size(); i++){
		if(s[i]=='R') break;
	}
	if(i){
		int frh = i;
		for(; i<s.size(); i++) rx+=s[i];
		dfs(rx, a, b+frh, prob);
		return;
	}
	for(i=1; i<s.size(); i++){
		if(s[i]=='H') break;
	}
	if(i == s.size()){
		dfs("", a+s.size(), b, prob);
		return;
	}
	for(int t=0; t<i-1; t++) rx+='R', hx+='R';
	rx+='H', hx+='R';
	for(int t=i+1; t<s.size(); t++) rx+=s[t], hx+=s[t];
	dfs(rx, a, b, prob*r%mod);
	dfs(hx, a, b, prob*h%mod);
}

int main(){
	scanf("%d%lld%lld", &N, &r, &h), rh=ex(r+h,mod-2);
	r=r*rh%mod, h=h*rh%mod;
	scanf("\n%s", st);
	scanf("%d%d", &A, &B);
	dfs(st, 0, 0, 1);
	printf("%lld\n", sum);
	return 0;
}

Compilation message

dstorv.cpp: In function 'void dfs(std::__cxx11::string, int, int, lld)':
dstorv.cpp:28:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=0; i<s.size(); i++){
           ~^~~~~~~~~
dstorv.cpp:33:10: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(; i<s.size(); i++) rx+=s[i];
         ~^~~~~~~~~
dstorv.cpp:37:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(i=1; i<s.size(); i++){
           ~^~~~~~~~~
dstorv.cpp:40:7: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(i == s.size()){
     ~~^~~~~~~~~~~
dstorv.cpp:46:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int t=i+1; t<s.size(); t++) rx+=s[t], hx+=s[t];
                 ~^~~~~~~~~
dstorv.cpp: In function 'int main()':
dstorv.cpp:52:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%lld%lld", &N, &r, &h), rh=ex(r+h,mod-2);
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
dstorv.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("\n%s", st);
  ~~~~~^~~~~~~~~~~~
dstorv.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &A, &B);
  ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 2 ms 524 KB Output is correct
10 Correct 2 ms 524 KB Output is correct
11 Correct 2 ms 524 KB Output is correct
12 Correct 2 ms 524 KB Output is correct
13 Correct 2 ms 524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 536 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 484 KB Output is correct
6 Correct 3 ms 524 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 2 ms 524 KB Output is correct
9 Correct 2 ms 524 KB Output is correct
10 Correct 2 ms 524 KB Output is correct
11 Correct 2 ms 524 KB Output is correct
12 Correct 2 ms 524 KB Output is correct
13 Correct 2 ms 524 KB Output is correct
14 Execution timed out 1079 ms 536 KB Time limit exceeded
15 Halted 0 ms 0 KB -