답안 #144793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144793 2019-08-17T18:28:59 Z arayi Ljetopica (COI19_ljetopica) C++17
100 / 100
177 ms 63736 KB
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#define fr first
#define sc second
#define MP make_pair
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
using namespace std;

lli gcd(lli a, lli b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
lli cg(lli n) {
	return n ^ (n >> 1);
}
lli SUM(lli a)
{
	return (a * (a + 1) / 2);
}
bool CAN(int x, int y, int n, int m)
{
	if (x >= 0 && y >= 0 && x < n && y < m)
	{
		return true;
	}
	return false;
}
double her(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string strsum(string a, string b)
{
	int p = 0;
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (b.length() < a.length())
	{
		for (int i = b.length(); i < a.length(); i++)
		{
			b += "0";
		}
	}
	else
	{
		for (int i = a.length(); i < b.length(); i++)
		{
			a += "0";
		}
	}

	a += "0", b += "0";
	for (int i = 0; i < a.length(); i++)
	{
		c += (a[i] - '0' + b[i] - '0' + p) % 10 + '0';
		p = (a[i] + b[i] - '0' - '0' + p) / 10;
	}
	if (c[c.length() - 1] == '0') c.erase(c.length() - 1, 1);
	reverse(c.begin(), c.end());
	return c;
}
string strmin(string a, string b)
{
	if (a.length() > b.length()) return b;
	if (b.length() > a.length()) return a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] > b[i]) return b;
		if (b[i] > a[i]) return a;
	}
	return a;
}

char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };



const int N = 1e6 + 30;
const lli mod = 1000000007;

int n, k;
lli pat;
string s, A, B, t;
lli dp[1010][1010][2][2], dpq[1010][1010][2][2];
lli dm()
{
	dp[0][0][0][1] = 1;
	dp[0][0][1][1] = 1;
	dpq[0][0][0][1] = 1;
	dpq[0][0][1][1] = 1;
	for (int i = 0; i < n - 1; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			for (int k = 0; k < 2; k++)
			{
				//cout << k << " " << s[i] << endl;
				if ((k == 0 && s[i] == 'R') || (k == 1 && s[i] == 'L'))
				{
					if (t[i + 1] == '0')
					{
						dp[i + 1][j + 1][k ^ 1][1] += dp[i][j][k][1] * 2;
						dp[i + 1][j + 1][k ^ 1][1] %= mod;
						dpq[i + 1][j + 1][k ^ 1][1] += dpq[i][j][k][1];
						dpq[i + 1][j + 1][k ^ 1][1] %= mod;
					}
					else
					{
						dp[i + 1][j][k][1] += (dp[i][j][k][1] * 2 + dpq[i][j][k][1]);
						dp[i + 1][j][k][1] %= mod;
						//cout << dp[i + 1][j][k][1] << endl;
						dpq[i + 1][j][k][1] += dpq[i][j][k][1];
						dpq[i + 1][j][k][1] %= mod;
						dp[i + 1][j + 1][k ^ 1][0] += dp[i][j][k][1] * 2;
						dp[i + 1][j + 1][k ^ 1][0] %= mod;
						dpq[i + 1][j + 1][k ^ 1][0] += dpq[i][j][k][1];
						dpq[i + 1][j + 1][k ^ 1][0] %= mod;
					}
					dp[i + 1][j][k][0] += (dp[i][j][k][0] * 2 + dpq[i][j][k][0]);
					dp[i + 1][j][k][0] %= mod;
					dpq[i + 1][j][k][0] += dpq[i][j][k][0];
					dpq[i + 1][j][k][0] %= mod;
					dp[i + 1][j + 1][k ^ 1][0] += dp[i][j][k][0] * 2;
					dp[i + 1][j + 1][k ^ 1][0] %= mod;
					dpq[i + 1][j + 1][k ^ 1][0] += dpq[i][j][k][0];
					dpq[i + 1][j + 1][k ^ 1][0] %= mod;
				}
				else
				{
					if (t[i + 1] == '0')
					{
						dp[i + 1][j][k][1] += dp[i][j][k][1] * 2;
						dp[i + 1][j][k][1] %= mod;
						dpq[i + 1][j][k][1] += dpq[i][j][k][1];
						dpq[i + 1][j][k][1] %= mod;
					}
					else
					{
						dp[i + 1][j][k][0] += dp[i][j][k][1] * 2;
						dp[i + 1][j][k][0] %= mod;
						dpq[i + 1][j][k][0] += dpq[i][j][k][1];
						dpq[i + 1][j][k][0] %= mod;
						dp[i + 1][j + 1][k ^ 1][1] += (dp[i][j][k][1] * 2 + dpq[i][j][k][1]);
						dp[i + 1][j + 1][k ^ 1][1] %= mod;
						dpq[i + 1][j + 1][k ^ 1][1] += dpq[i][j][k][1];
						dpq[i + 1][j + 1][k ^ 1][1] %= mod;
					}
					dp[i + 1][j][k][0] += dp[i][j][k][0] * 2;
					dp[i + 1][j][k][0] %= mod;
					dpq[i + 1][j][k][0] += dpq[i][j][k][0];
					dpq[i + 1][j][k][0] %= mod;
					dp[i + 1][j + 1][k ^ 1][0] += (dp[i][j][k][0] * 2 + dpq[i][j][k][0]);
					dp[i + 1][j + 1][k ^ 1][0] %= mod;
					dpq[i + 1][j + 1][k ^ 1][0] += dpq[i][j][k][0];
					dpq[i + 1][j + 1][k ^ 1][0] %= mod;
				}
				
			}
		}
	}
	lli sm = (dp[n - 1][k][0][0] + dp[n - 1][k][0][1] + dp[n - 1][k][1][0] + dp[n - 1][k][1][1]) % mod;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			for (int k = 0; k < 2; k++)
			{
				dp[i][j][k][0] = 0;
				dp[i][j][k][1] = 0;
				dpq[i][j][k][0] = 0;
				dpq[i][j][k][1] = 0;
			}
		}
	}
	return sm;
}

int main()
{
	fastio;
	cin >> n >> k;
	cin >> s >> A >> B;
	t = B;
	pat = dm();
	//cout << pat << endl;
	for (int i = 1; i < A.length(); i++)
	{
		if (A[i] == '1')
		{
			for (int i = A.length() - 1; i >= 0; i--)
			{
				if (A[i] == '0')
					A[i] = '1';
				else
				{
					A[i] = '0';
					break;
				}
			}
			t = A;
			pat -= dm();
			if (pat < 0) pat += mod;
			cout << pat;
			return 0;
		}
	}
	
	//cout << t << endl;
	//cout << dm() << endl;
	
	cout << pat;
	return 0;
}

Compilation message

ljetopica.cpp: In function 'std::__cxx11::string strsum(std::__cxx11::string, std::__cxx11::string)':
ljetopica.cpp:57:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = b.length(); i < a.length(); i++)
                            ~~^~~~~~~~~~~~
ljetopica.cpp:64:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = a.length(); i < b.length(); i++)
                            ~~^~~~~~~~~~~~
ljetopica.cpp:71:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.length(); i++)
                  ~~^~~~~~~~~~~~
ljetopica.cpp: In function 'std::__cxx11::string strmin(std::__cxx11::string, std::__cxx11::string)':
ljetopica.cpp:84:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.length(); i++)
                  ~~^~~~~~~~~~~~
ljetopica.cpp: In function 'int main()':
ljetopica.cpp:206:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < A.length(); i++)
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 8568 KB Output is correct
2 Correct 12 ms 8188 KB Output is correct
3 Correct 11 ms 7800 KB Output is correct
4 Correct 10 ms 7288 KB Output is correct
5 Correct 10 ms 6904 KB Output is correct
6 Correct 10 ms 6520 KB Output is correct
7 Correct 8 ms 6136 KB Output is correct
8 Correct 9 ms 5800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 2 ms 632 KB Output is correct
4 Correct 3 ms 632 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 632 KB Output is correct
7 Correct 3 ms 632 KB Output is correct
8 Correct 2 ms 632 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 2 ms 504 KB Output is correct
13 Correct 3 ms 632 KB Output is correct
14 Correct 2 ms 504 KB Output is correct
15 Correct 2 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 44384 KB Output is correct
2 Correct 76 ms 33300 KB Output is correct
3 Correct 85 ms 36856 KB Output is correct
4 Correct 177 ms 63736 KB Output is correct
5 Correct 71 ms 31864 KB Output is correct
6 Correct 163 ms 63708 KB Output is correct
7 Correct 48 ms 22648 KB Output is correct
8 Correct 84 ms 36428 KB Output is correct
9 Correct 15 ms 9720 KB Output is correct
10 Correct 76 ms 33780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 8568 KB Output is correct
2 Correct 12 ms 8188 KB Output is correct
3 Correct 11 ms 7800 KB Output is correct
4 Correct 10 ms 7288 KB Output is correct
5 Correct 10 ms 6904 KB Output is correct
6 Correct 10 ms 6520 KB Output is correct
7 Correct 8 ms 6136 KB Output is correct
8 Correct 9 ms 5800 KB Output is correct
9 Correct 3 ms 632 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 2 ms 632 KB Output is correct
12 Correct 3 ms 632 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 632 KB Output is correct
15 Correct 3 ms 632 KB Output is correct
16 Correct 2 ms 632 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 2 ms 504 KB Output is correct
21 Correct 3 ms 632 KB Output is correct
22 Correct 2 ms 504 KB Output is correct
23 Correct 2 ms 632 KB Output is correct
24 Correct 105 ms 44384 KB Output is correct
25 Correct 76 ms 33300 KB Output is correct
26 Correct 85 ms 36856 KB Output is correct
27 Correct 177 ms 63736 KB Output is correct
28 Correct 71 ms 31864 KB Output is correct
29 Correct 163 ms 63708 KB Output is correct
30 Correct 48 ms 22648 KB Output is correct
31 Correct 84 ms 36428 KB Output is correct
32 Correct 15 ms 9720 KB Output is correct
33 Correct 76 ms 33780 KB Output is correct
34 Correct 131 ms 52756 KB Output is correct
35 Correct 51 ms 23032 KB Output is correct
36 Correct 76 ms 33144 KB Output is correct
37 Correct 158 ms 60624 KB Output is correct
38 Correct 32 ms 14968 KB Output is correct
39 Correct 142 ms 57072 KB Output is correct
40 Correct 27 ms 13944 KB Output is correct
41 Correct 94 ms 40668 KB Output is correct
42 Correct 124 ms 50012 KB Output is correct
43 Correct 119 ms 49652 KB Output is correct
44 Correct 137 ms 56912 KB Output is correct
45 Correct 47 ms 21752 KB Output is correct
46 Correct 109 ms 46064 KB Output is correct
47 Correct 117 ms 48376 KB Output is correct
48 Correct 75 ms 30952 KB Output is correct
49 Correct 16 ms 9336 KB Output is correct
50 Correct 147 ms 55032 KB Output is correct
51 Correct 104 ms 29176 KB Output is correct
52 Correct 70 ms 30584 KB Output is correct
53 Correct 173 ms 63624 KB Output is correct
54 Correct 51 ms 23516 KB Output is correct
55 Correct 131 ms 53852 KB Output is correct
56 Correct 145 ms 60208 KB Output is correct
57 Correct 25 ms 13736 KB Output is correct
58 Correct 125 ms 48636 KB Output is correct