답안 #66558

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66558 2018-08-11T12:14:27 Z imsifile 디스토브 (FXCUP3_dstorv) C++
100 / 100
296 ms 129300 KB
#include<stdio.h>

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, dy1[5050][5050], dy2[5050][5050];
int N, A, B, x, y, xys[5050][2], xyc;
int chk[5050][5050];
char st[5050];

void make_route(int s){
	int pv=0;
	for(int i=s; i<N; i++){
		if(st[i]=='R'){
			if(pv==-1) xys[xyc][0]=x, xys[xyc][1]=y, xyc++;
			else chk[x][y]|=2;
			y++, pv=1;
		}
		else{
			if(pv==1) chk[x][y]|=3;
			chk[x][y]|=1;
			x++, pv=-1;
		}
	}
	chk[0][0]=0;
}

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);
	while(N){
		if(st[N-1] != 'R') break;
		N--, A--;
	}
	st[N]=0;
	for(int i=0; i<=N; i++){
		if(i==N || st[i] != 'H'){
			make_route(i);
			N -= i;
			break;
		}
		B--;
	}
	if(A<0 || B<0){ puts("0"); return 0; }
	if(N==0){
		puts(A==0&&B==0 ? "1" : "0");
		return 0;
	}

	dy1[B][0]=1;
	for(int i=0; i<=x; i++){
		for(int j=1; j<=y; j++){
			if(chk[i][j]&2) continue;
			dy1[i][j] += dy1[i][j-1]*r;
			if(i) dy1[i][j] += dy1[i-1][j]*h;
			dy1[i][j] %= mod;
		}
	}
	dy2[x][y-A]=1;
	for(int i=x-1; i>=0; i--){
		for(int j=y; j>=0; j--){
			if(chk[i][j]&1) continue;
			dy2[i][j] += dy2[i][j+1]*r;
			dy2[i][j] += dy2[i+1][j]*h;
			dy2[i][j] %= mod;
		}
	}
	if(A==0){ printf("%lld\n", dy1[x][y]); return 0; }
	if(B==0){ printf("%lld\n", dy2[0][0]); return 0; }

	lld sum=0;
	for(int i=0; i<xyc; i++){
		int r=xys[i][0], c=xys[i][1];
		sum += dy1[r][c]*dy2[r][c];
		sum %= mod;
	}
	printf("%lld\n", sum);
	return 0;
}

Compilation message

dstorv.cpp: In function 'int main()':
dstorv.cpp:38: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:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("\n%s", st);
  ~~~~~^~~~~~~~~~~~
dstorv.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &A, &B);
  ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 356 KB Output is correct
4 Correct 2 ms 392 KB Output is correct
5 Correct 2 ms 440 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1172 KB Output is correct
2 Correct 24 ms 13652 KB Output is correct
3 Correct 119 ms 64328 KB Output is correct
4 Correct 267 ms 128600 KB Output is correct
5 Correct 247 ms 128600 KB Output is correct
6 Correct 2 ms 128600 KB Output is correct
7 Correct 2 ms 128600 KB Output is correct
8 Correct 2 ms 128600 KB Output is correct
9 Correct 279 ms 128600 KB Output is correct
10 Correct 282 ms 128600 KB Output is correct
11 Correct 276 ms 128600 KB Output is correct
12 Correct 296 ms 128600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 356 KB Output is correct
4 Correct 2 ms 392 KB Output is correct
5 Correct 2 ms 440 KB Output is correct
6 Correct 2 ms 568 KB Output is correct
7 Correct 2 ms 568 KB Output is correct
8 Correct 2 ms 568 KB Output is correct
9 Correct 2 ms 568 KB Output is correct
10 Correct 2 ms 568 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 2 ms 596 KB Output is correct
14 Correct 2 ms 1172 KB Output is correct
15 Correct 24 ms 13652 KB Output is correct
16 Correct 119 ms 64328 KB Output is correct
17 Correct 267 ms 128600 KB Output is correct
18 Correct 247 ms 128600 KB Output is correct
19 Correct 2 ms 128600 KB Output is correct
20 Correct 2 ms 128600 KB Output is correct
21 Correct 2 ms 128600 KB Output is correct
22 Correct 279 ms 128600 KB Output is correct
23 Correct 282 ms 128600 KB Output is correct
24 Correct 276 ms 128600 KB Output is correct
25 Correct 296 ms 128600 KB Output is correct
26 Correct 13 ms 128600 KB Output is correct
27 Correct 108 ms 128600 KB Output is correct
28 Correct 220 ms 128600 KB Output is correct
29 Correct 259 ms 129024 KB Output is correct
30 Correct 276 ms 129024 KB Output is correct
31 Correct 288 ms 129024 KB Output is correct
32 Correct 263 ms 129300 KB Output is correct
33 Correct 261 ms 129300 KB Output is correct
34 Correct 289 ms 129300 KB Output is correct
35 Correct 256 ms 129300 KB Output is correct
36 Correct 272 ms 129300 KB Output is correct
37 Correct 2 ms 129300 KB Output is correct
38 Correct 3 ms 129300 KB Output is correct
39 Correct 2 ms 129300 KB Output is correct
40 Correct 264 ms 129300 KB Output is correct
41 Correct 270 ms 129300 KB Output is correct
42 Correct 267 ms 129300 KB Output is correct
43 Correct 2 ms 129300 KB Output is correct
44 Correct 32 ms 129300 KB Output is correct
45 Correct 263 ms 129300 KB Output is correct