답안 #234757

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
234757 2020-05-25T13:19:04 Z amoo_safar Ljetopica (COI19_ljetopica) C++14
100 / 100
187 ms 64380 KB
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 1e3 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 30;

str t;
int n, k, ss[N];
ll dp[N][N][2][2];
ll cnt[N][N][2][2];

int fl = 1;
ll Solve(str s){
	memset(dp, 0, sizeof dp);
	memset(cnt, 0, sizeof cnt);
	if(s[0] == '1'){
		dp[0][0][0][0] = 1;
		dp[0][0][1][1] = 1;
		dp[0][1][0][0] = 1;
		dp[0][1][1][1] = 1;

		cnt[0][0][0][0] = 2;
		cnt[0][0][1][1] = 3;
		cnt[0][1][0][0] = 2;
		cnt[0][1][1][1] = 3;
	} else {
		dp[0][0][0][1] = 1;
		dp[0][1][0][1] = 1;

		cnt[0][0][0][1] = 2;
		cnt[0][1][0][1] = 2;
	}
	int nb;
	for(int i = 0; i + 1 < n; i++){
		for(int j = 0; j < n; j++){
			for(int la = 0; la < 2; la++)
			for(int b = 0; b < 2; b++){
				for(int nx = 0; nx < 2; nx ++){
					if(b && nx > (s[i+1] - '0')) continue;
					if(b && nx == (s[i+1] - '0')) nb = 1;
					else nb = 0;
					(dp[i + 1][j + (nx ^ la ^ ss[i] ^ ss[i + 1])][nx][nb] += dp[i][j][la][b]) %= Mod;
					(cnt[i + 1][j + (nx ^ la ^ ss[i] ^ ss[i + 1])][nx][nb] += cnt[i][j][la][b]*2 + dp[i][j][la][b]*nx) %= Mod;	
				}
			}
		}
	}
	ll ans = 0;
	for(int la = 0; la < 2; la++) ans += cnt[n - 1][k][la][0];
	if(fl) for(int la = 0; la < 2; la++) ans += cnt[n - 1][k][la][1];
	//cerr << ans % Mod << '\n';
	return ans % Mod;
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	cin >> t;
	for(int i = 0; i < n-1; i++) ss[i] = (t[i] == 'R');
	str A, B;
	cin >> A >> B;
	assert((int) B.size() == n);
	assert((int) A.size() == n);
	n --;
	ll res = Solve(B.substr(1));
	fl = 0;
	res -= Solve(A.substr(1));
	res += Mod;
	cout << res % Mod << '\n';
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 64256 KB Output is correct
2 Correct 161 ms 64248 KB Output is correct
3 Correct 150 ms 64376 KB Output is correct
4 Correct 137 ms 64256 KB Output is correct
5 Correct 128 ms 64276 KB Output is correct
6 Correct 118 ms 64256 KB Output is correct
7 Correct 110 ms 64248 KB Output is correct
8 Correct 99 ms 64248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 64248 KB Output is correct
2 Correct 45 ms 64248 KB Output is correct
3 Correct 45 ms 64248 KB Output is correct
4 Correct 45 ms 64248 KB Output is correct
5 Correct 45 ms 64256 KB Output is correct
6 Correct 45 ms 64256 KB Output is correct
7 Correct 45 ms 64256 KB Output is correct
8 Correct 45 ms 64256 KB Output is correct
9 Correct 46 ms 64256 KB Output is correct
10 Correct 45 ms 64248 KB Output is correct
11 Correct 44 ms 64256 KB Output is correct
12 Correct 45 ms 64248 KB Output is correct
13 Correct 44 ms 64256 KB Output is correct
14 Correct 45 ms 64256 KB Output is correct
15 Correct 45 ms 64248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 64256 KB Output is correct
2 Correct 171 ms 64376 KB Output is correct
3 Correct 172 ms 64380 KB Output is correct
4 Correct 171 ms 64276 KB Output is correct
5 Correct 172 ms 64376 KB Output is correct
6 Correct 174 ms 64248 KB Output is correct
7 Correct 171 ms 64256 KB Output is correct
8 Correct 171 ms 64248 KB Output is correct
9 Correct 176 ms 64252 KB Output is correct
10 Correct 172 ms 64280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 64256 KB Output is correct
2 Correct 161 ms 64248 KB Output is correct
3 Correct 150 ms 64376 KB Output is correct
4 Correct 137 ms 64256 KB Output is correct
5 Correct 128 ms 64276 KB Output is correct
6 Correct 118 ms 64256 KB Output is correct
7 Correct 110 ms 64248 KB Output is correct
8 Correct 99 ms 64248 KB Output is correct
9 Correct 47 ms 64248 KB Output is correct
10 Correct 45 ms 64248 KB Output is correct
11 Correct 45 ms 64248 KB Output is correct
12 Correct 45 ms 64248 KB Output is correct
13 Correct 45 ms 64256 KB Output is correct
14 Correct 45 ms 64256 KB Output is correct
15 Correct 45 ms 64256 KB Output is correct
16 Correct 45 ms 64256 KB Output is correct
17 Correct 46 ms 64256 KB Output is correct
18 Correct 45 ms 64248 KB Output is correct
19 Correct 44 ms 64256 KB Output is correct
20 Correct 45 ms 64248 KB Output is correct
21 Correct 44 ms 64256 KB Output is correct
22 Correct 45 ms 64256 KB Output is correct
23 Correct 45 ms 64248 KB Output is correct
24 Correct 171 ms 64256 KB Output is correct
25 Correct 171 ms 64376 KB Output is correct
26 Correct 172 ms 64380 KB Output is correct
27 Correct 171 ms 64276 KB Output is correct
28 Correct 172 ms 64376 KB Output is correct
29 Correct 174 ms 64248 KB Output is correct
30 Correct 171 ms 64256 KB Output is correct
31 Correct 171 ms 64248 KB Output is correct
32 Correct 176 ms 64252 KB Output is correct
33 Correct 172 ms 64280 KB Output is correct
34 Correct 173 ms 64248 KB Output is correct
35 Correct 151 ms 64248 KB Output is correct
36 Correct 159 ms 64248 KB Output is correct
37 Correct 171 ms 64276 KB Output is correct
38 Correct 153 ms 64256 KB Output is correct
39 Correct 152 ms 64376 KB Output is correct
40 Correct 156 ms 64376 KB Output is correct
41 Correct 164 ms 64256 KB Output is correct
42 Correct 171 ms 64248 KB Output is correct
43 Correct 161 ms 64256 KB Output is correct
44 Correct 150 ms 64256 KB Output is correct
45 Correct 155 ms 64276 KB Output is correct
46 Correct 154 ms 64248 KB Output is correct
47 Correct 159 ms 64376 KB Output is correct
48 Correct 156 ms 64248 KB Output is correct
49 Correct 154 ms 64248 KB Output is correct
50 Correct 166 ms 64376 KB Output is correct
51 Correct 162 ms 64256 KB Output is correct
52 Correct 166 ms 64248 KB Output is correct
53 Correct 173 ms 64376 KB Output is correct
54 Correct 173 ms 64248 KB Output is correct
55 Correct 171 ms 64248 KB Output is correct
56 Correct 183 ms 64376 KB Output is correct
57 Correct 187 ms 64252 KB Output is correct
58 Correct 172 ms 64276 KB Output is correct