답안 #1041711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1041711 2024-08-02T07:19:50 Z vjudge1 Ljetopica (COI19_ljetopica) C++17
22 / 100
63 ms 9048 KB
#include <iostream>
#include <vector>
#include <set>

using namespace std;
const int N = (1<<26);
int tp[50000], mod = 1e9 + 7;
string s, l, r;

void solve1(int n, int k){
	vector<bool> Cnt(N, 0);
	int L = 0, R = 0;
	for (int i=0;i<n;i++){
		if (l[i] == '1')
			L += tp[n - i - 1];
		if (r[i] == '1')
			R += tp[n - i - 1];
	}


	long long Sum = 0;
	int KK = 1<<(n-1);
	for (int mask=0;mask<(1<<(n-1));mask++){
		// mask = 6;
		if (__builtin_popcount(mask) != k)
			continue;
		int num = 0;
		int cnt = 0;
		for (int j=0, k = n-2;j<n-1;j++, k--){
			if ((1<<k) & mask)
				cnt = cnt + 1;
			if (cnt == 2)
				cnt = 0;
			if ((cnt == 1 and s[j] == 'L') or (cnt == 0 and s[j] == 'R'))
				num += (1<<k);
			// cout<<cnt<<" "<<s[j]<<'\n';
		}

		int num2 = num;
		num += KK;
		if (num >= L and num <= R and Cnt[num] == 0){
			Sum += num;
			// cout<<num<<" "<<mask<<'\n';
		}

		Cnt[num] = 1;
		num = KK - num2 - 1;
		num += KK;
		if (num >= L and num <= R and Cnt[num] == 0)
			Sum += num/*, cout<<num<<" A "<<mask<<'\n'*/;
		Cnt[num] = 1;
		// mask = 8;
	}

	cout<<Sum % mod<<'\n';

	exit(0);
}

int main(){
	tp[0] = 1;
	for (int i=1;i<50000;i++)
		tp[i] = (tp[i-1] + tp[i-1]) % mod;

	int n, k;
	cin>>n>>k;

	

	string p1 = "1", p2 = "1";
	cin>>s>>l>>r;
	while (l.size() < n)
		l = '0' + l;
	while (r.size() < n)
		r = '0' + r;

	if (n <= 25)
		solve1(n, k);
	
	

	for (int i=0;i<n-1;i++){
		if (s[i] == 'L')
			p1 += '0', p2 += '1';
		else
			p1 += '1', p2 += '0';
	}

	int Ans = 0;
	for (auto i : {p1, p2}){
		if (i > r or i < l)
			continue;
		for (int j=0;j<i.size();j++)
			if (i[j] == '1')
				Ans = (Ans + tp[i.size() - 1 - j]) % mod;
	}
	cout<<Ans<<'\n';

}

Compilation message

ljetopica.cpp: In function 'int main()':
ljetopica.cpp:72:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |  while (l.size() < n)
      |         ~~~~~~~~~^~~
ljetopica.cpp:74:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   74 |  while (r.size() < n)
      |         ~~~~~~~~~^~~
ljetopica.cpp:93:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for (int j=0;j<i.size();j++)
      |                ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 8832 KB Output is correct
2 Correct 4 ms 9048 KB Output is correct
3 Correct 33 ms 8796 KB Output is correct
4 Correct 33 ms 8796 KB Output is correct
5 Correct 20 ms 8796 KB Output is correct
6 Correct 50 ms 8792 KB Output is correct
7 Correct 33 ms 8792 KB Output is correct
8 Correct 31 ms 8796 KB Output is correct
9 Correct 5 ms 8796 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 17 ms 8824 KB Output is correct
12 Correct 3 ms 8796 KB Output is correct
13 Correct 31 ms 8796 KB Output is correct
14 Correct 5 ms 8860 KB Output is correct
15 Correct 10 ms 8796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 0 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 63 ms 8832 KB Output is correct
10 Correct 4 ms 9048 KB Output is correct
11 Correct 33 ms 8796 KB Output is correct
12 Correct 33 ms 8796 KB Output is correct
13 Correct 20 ms 8796 KB Output is correct
14 Correct 50 ms 8792 KB Output is correct
15 Correct 33 ms 8792 KB Output is correct
16 Correct 31 ms 8796 KB Output is correct
17 Correct 5 ms 8796 KB Output is correct
18 Correct 3 ms 8796 KB Output is correct
19 Correct 17 ms 8824 KB Output is correct
20 Correct 3 ms 8796 KB Output is correct
21 Correct 31 ms 8796 KB Output is correct
22 Correct 5 ms 8860 KB Output is correct
23 Correct 10 ms 8796 KB Output is correct
24 Incorrect 0 ms 604 KB Output isn't correct
25 Halted 0 ms 0 KB -