답안 #896725

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896725 2024-01-02T02:10:29 Z LCJLY Linear Garden (IOI08_linear_garden) C++14
0 / 100
29 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << "  " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << "  " << j << " " << #i << "  " << q << " " << #p << endl; 
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;

int n,mod;
int arr[1000005];
int memo[1000005][3][3][2];

int dp(int index, int lotus, int pap, bool bound){
	if(index==n) return 1;
	if(memo[index][lotus][pap][bound]!=-1) return memo[index][lotus][pap][bound];
	int ans=0;
	
	if(bound){
		for(int x=1;x<=arr[index];x++){
			int hold=lotus;
			int hold2=pap;
			if(x==1){
				hold++;
				hold2=max(0LL,hold2-1);
			}
			else{
				hold2++;
				hold=max(0LL,hold-1);
			}
			
			if(hold>2||hold2>2) continue;
			ans=(ans+dp(index+1,hold,hold2,x==arr[index]))%mod;
		}
	}
	else{
		for(int x=1;x<=2;x++){
			int hold=lotus;
			int hold2=pap;
			if(x==1){
				hold++;
				hold2=max(0LL,hold2-1);
			}
			else{
				hold2++;
				hold=max(0LL,hold-1);
			}
			
			if(hold>2||hold2>2) continue;
			ans=(ans+dp(index+1,hold,hold2,false))%mod;
		}
	}
	return ans;
}

void solve(){	
	cin >> n >> mod;
	
	string s;
	cin >> s;
	
	for(int x=0;x<n;x++){
		if(s[x]=='L') arr[x]=1;
		else arr[x]=2;
	}
	
	memset(memo,-1,sizeof(memo));
	cout << dp(0,0,0,1);
	
}

int32_t main(){										
	ios::sync_with_stdio(0);	
	cin.tie(0);
	//freopen("out.txt", "w", stdout);
	int t=1;
	//cin >> t;
	while(t--){
		solve();
	}	
}





		


		
		
	
# 결과 실행 시간 메모리 Grader output
1 Runtime error 17 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 12 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 27 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 15 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 29 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 16 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -