Submission #144225

# Submission time Handle Problem Language Result Execution time Memory
144225 2019-08-16T10:11:55 Z arayi Ljetopica (COI19_ljetopica) C++17
8 / 100
285 ms 376 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;
string s, A, B;
lli pat[1010], c[1010][1010], ans;
lli erku(int i1)
{
	lli res = 1;
	for (int i = 0; i < i1; i++)
	{
		res *= 2;
		res %= mod;
	}
	return res;
}
lli tv(string a)
{
	lli res = erku(a.length());
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] == '1')
		{
			res += erku(a.length() - i - 1);
			res %= mod;
		}
	}
	return res;
}
lli kk(lli a, lli b)
{
	int res = 0;
	for (int i = 0; i < n; i++)
	{
		if (((1LL << i) & a) != ((1LL << i) & b))
		{
			res++;
		}
	}
	if (res == k)
		return b;
	return 0;
}
int main()
{
	fastio;
	//freopen("c.in", "r", stdin);
	cin >> n >> k >> s >> A >> B;
	A.erase(0, 1);
	B.erase(0, 1);
	for (int i = 0; i < n - 1; i++)
	{
		if (s[i] == 'L') s[i] = '0';
		else s[i] = '1';
	}
	if (k == 0)
	{
		if (strmin(s, A) == A && strmin(s, B) == s)
			ans += tv(s), ans %= mod;
		for (int i = 0; i < n - 1; i++)
		{
			if (s[i] == '1') s[i] = '0';
			else s[i] = '1';
		}
		if (strmin(s, A) == A && strmin(s, B) == s)
			ans += tv(s), ans %= mod;
	}
	if (n <= 25)
	{
		lli sm1 = tv(s);
		lli sm2 = tv(A);
		lli sm3 = tv(B);
		//cout << sm1 << " " << sm2 << " " << sm3 << endl;
		for (lli i = sm2; i < sm3; i++)
		{
			ans += kk(sm1, i);
			ans %= mod;
		}
		for (int i = 0; i < n - 1; i++)
		{
			if (s[i] == '1') s[i] = '0';
			else s[i] = '1';
		}
		if (((n - 1) % 2 > 0) || ((n - 1) / 2) != k)
		{
			sm1 = tv(s);
			//cout << sm1;
			for (lli i = sm2; i < sm3; i++)
			{
				ans += kk(sm1, i);
				ans %= mod;
			}
		}
	}
	cout << ans;
	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 'long long int tv(std::__cxx11::string)':
ljetopica.cpp:117:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.length(); i++)
                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 285 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 4 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Incorrect 285 ms 376 KB Output isn't correct
10 Halted 0 ms 0 KB -