Codeforces Round 957 (Div. 3)

🚀欢迎来到本文🚀
🍉个人简介:陈童学哦,彩笔ACMer一枚。
🏀所属专栏:Codeforces
本文用于记录回顾总结个人的一些解题思路便于加深理解。

在这里插入图片描述

A. Only Pluses

Kmes has written three integers a a a, b b b and c c c in order to remember that he has to give Noobish_Monk a × b × c a \times b \times c a×b×c bananas.

Noobish_Monk has found these integers and decided to do the following at most 5 5 5 times:

  • pick one of these integers;
  • increase it by 1 1 1.

For example, if a = 2 a = 2 a=2, b = 3 b = 3 b=3 and c = 4 c = 4 c=4, then one can increase a a a three times by one and increase b b b two times. After that a = 5 a = 5 a=5, b = 5 b = 5 b=5, c = 4 c = 4 c=4. Then the total number of bananas will be 5 × 5 × 4 = 100 5 \times 5 \times 4 = 100 5×5×4=100.

What is the maximum value of a × b × c a \times b \times c a×b×c Noobish_Monk can achieve with these operations?

在这里插入图片描述
Input

Each test contains multiple test cases. The first line of input contains a single integer t t t ( 1 ≤ t ≤ 1000 1 \le t \le 1000 1t1000) — the number of test cases. The description of the test cases follows.

The first and only line of each test case contains three integers a a a, b b b and c c c ( 1 ≤ a , b , c ≤ 10 1 \le a, b, c \le 10 1a,b,c10) — Kmes’s integers.

在这里插入图片描述
Output

For each test case, output a single integer — the maximum amount of bananas Noobish_Monk can get.

在这里插入图片描述

解题思路

暴力枚举即可。

AC代码

#include<bits/stdc++.h>
#define look(x) cout << #x << " ==  " << x << "\n"
using namespace std;
using i64 = long long;
const int N = 5e5 + 10;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve(){
	int a,b,c;
	cin >> a >> b >> c;
	int ans = a * b * c;
	for(int i = 0;i <= 5;i ++){
		for(int j = 0;j <= 5;j ++){
			for(int k = 0;k <= 5;k ++){
				if(i + j + k <= 5){
					ans = max(ans,(a + i) * (b + j) * (c + k));
				}
			}
		}
	}	
	cout << ans << "\n";
}
int main(){	

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	
	int t = 1;
	cin >> t;

	while(t --){
		solve();
	}
	
	return 0;
}

B. Angry Monk

To celebrate his recovery, k1o0n has baked an enormous n n n metres long potato casserole.

Turns out, Noobish_Monk just can’t stand potatoes, so he decided to ruin k1o0n’s meal. He has cut it into k k k pieces, of lengths a 1 , a 2 , … , a k a_1, a_2, \dots, a_k a1,a2,,ak meters.

k1o0n wasn’t keen on that. Luckily, everything can be fixed. In order to do that, k1o0n can do one of the following operations:

  • Pick a piece with length a i ≥ 2 a_i \ge 2 ai2 and divide it into two pieces with lengths 1 1 1 and a i − 1 a_i - 1 ai1. As a result, the number of pieces will increase by 1 1 1;
  • Pick a slice a i a_i ai and another slice with length a j = 1 a_j=1 aj=1 ( i ≠ j i \ne j i=j) and merge them into one piece with length a i + 1 a_i+1 ai+1. As a result, the number of pieces will decrease by 1 1 1.

Help k1o0n to find the minimum number of operations he needs to do in order to merge the casserole into one piece with length n n n.

For example, if n = 5 n=5 n=5, k = 2 k=2 k=2 and a = [ 3 , 2 ] a = [3, 2] a=[3,2], it is optimal to do the following:

  1. Divide the piece with length 2 2 2 into two pieces with lengths 2 − 1 = 1 2-1=1 21=1 and 1 1 1, as a result a = [ 3 , 1 , 1 ] a = [3, 1, 1] a=[3,1,1].
  2. Merge the piece with length 3 3 3 and the piece with length 1 1 1, as a result a = [ 4 , 1 ] a = [4, 1] a=[4,1].
  3. Merge the piece with length 4 4 4 and the piece with length 1 1 1, as a result a = [ 5 ] a = [5] a=[5].

在这里插入图片描述

Input

Each test contains multiple test cases. The first line contains the number of test cases t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104).

Description of each test case consists of two lines. The first line contains two integers n n n and k k k ( 2 ≤ n ≤ 1 0 9 2 \le n \le 10^9 2n109, 2 ≤ k ≤ 1 0 5 2 \le k \le 10^5 2k105) — length of casserole and the number of pieces.

The second line contains k k k integers a 1 , a 2 , … , a k a_1, a_2, \ldots, a_k a1,a2,,ak ( 1 ≤ a i ≤ n − 1 1 \le a_i \le n - 1 1ain1, ∑ a i = n \sum a_i = n ai=n) — lengths of pieces of casserole, which Noobish_Monk has cut.

It is guaranteed that the sum of k k k over all t t t test cases doesn’t exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

在这里插入图片描述
Output

For each test case, output the minimum number of operations K1o0n needs to restore his pie after the terror of Noobish_Monk.

在这里插入图片描述

解题思路

我们可以贪心的去处理,因为最终所有的土豆块要合成一块,那么我们肯定会把更小的土豆都合并到最大的那块上去。
而小的土豆块要与最大的土豆块合并的时必须先拆成长度全为1的土豆块,那么每个土豆块分解的这个操作的贡献就是 a [ i ] − 1 a[i] - 1 a[i]1了,然后我们还需要把这些分解出来1合并到最大的土豆块上去,这个操作的贡献就是 a [ i ] a[i] a[i]了,所以一个土豆块合并到最大的土豆块上的总贡献就是 2 a [ i ] − 1 2a[i] - 1 2a[i]1了。

AC代码

#include<bits/stdc++.h>
#define look(x) cout << #x << " ==  " << x << "\n"
using namespace std;
using i64 = long long;
const int N = 5e5 + 10;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve(){
	int n,k;
	cin >> n >> k;
	vector<int> a(k + 1);
	int ans = 0;
	for(int i = 1;i <= k;i ++){
		cin >> a[i];
	}
	sort(a.begin() + 1,a.end());
	for(int i = 1;i < k;i ++){
		if(a[i] != 1){
			ans += (2  * a[i] - 1);
		}else{
			ans ++;
		}
	}
	
	cout << ans << "\n";
	
}
int main(){	

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	
	int t = 1;
	cin >> t;

	while(t --){
		solve();
	}
	
	return 0;
}

C. Gorilla and Permutation

Gorilla and Noobish_Monk found three numbers n n n, m m m, and k k k (KaTeX parse error: Expected 'EOF', got '&' at position 3: m &̲lt; k). They decided to construct a permutation † ^{\dagger} of length n n n.

For the permutation, Noobish_Monk came up with the following function: g ( i ) g(i) g(i) is the sum of all the numbers in the permutation on a prefix of length i i i that are not greater than m m m. Similarly, Gorilla came up with the function f f f, where f ( i ) f(i) f(i) is the sum of all the numbers in the permutation on a prefix of length i i i that are not less than k k k. A prefix of length i i i is a subarray consisting of the first i i i elements of the original array.

For example, if n = 5 n = 5 n=5, m = 2 m = 2 m=2, k = 5 k = 5 k=5, and the permutation is [ 5 , 3 , 4 , 1 , 2 ] [5, 3, 4, 1, 2] [5,3,4,1,2], then:

  • f ( 1 ) = 5 f(1) = 5 f(1)=5, because 5 ≥ 5 5 \ge 5 55; g ( 1 ) = 0 g(1) = 0 g(1)=0, because KaTeX parse error: Expected 'EOF', got '&' at position 3: 5 &̲gt; 2;
  • f ( 2 ) = 5 f(2) = 5 f(2)=5, because KaTeX parse error: Expected 'EOF', got '&' at position 3: 3 &̲lt; 5; g ( 2 ) = 0 g(2) = 0 g(2)=0, because KaTeX parse error: Expected 'EOF', got '&' at position 3: 3 &̲gt; 2;
  • f ( 3 ) = 5 f(3) = 5 f(3)=5, because KaTeX parse error: Expected 'EOF', got '&' at position 3: 4 &̲lt; 5; g ( 3 ) = 0 g(3) = 0 g(3)=0, because KaTeX parse error: Expected 'EOF', got '&' at position 3: 4 &̲gt; 2;
  • f ( 4 ) = 5 f(4) = 5 f(4)=5, because KaTeX parse error: Expected 'EOF', got '&' at position 3: 1 &̲lt; 5; g ( 4 ) = 1 g(4) = 1 g(4)=1, because 1 ≤ 2 1 \le 2 12;
  • f ( 5 ) = 5 f(5) = 5 f(5)=5, because KaTeX parse error: Expected 'EOF', got '&' at position 3: 2 &̲lt; 5; g ( 5 ) = 1 + 2 = 3 g(5) = 1 + 2 = 3 g(5)=1+2=3, because 2 ≤ 2 2 \le 2 22.

Help them find a permutation for which the value of ( ∑ i = 1 n f ( i ) − ∑ i = 1 n g ( i ) ) \left(\sum_{i=1}^n f(i) - \sum_{i=1}^n g(i)\right) (i=1nf(i)i=1ng(i)) is maximized.

† ^{\dagger} A permutation of length n n n is an array consisting of n n n distinct integers from 1 1 1 to n n n in any order. For example, [ 2 , 3 , 1 , 5 , 4 ] [2,3,1,5,4] [2,3,1,5,4] is a permutation, but [ 1 , 2 , 2 ] [1,2,2] [1,2,2] is not a permutation (as 2 2 2 appears twice in the array) and [ 1 , 3 , 4 ] [1,3,4] [1,3,4] is also not a permutation (as n = 3 n=3 n=3, but 4 4 4 appears in the array).

在这里插入图片描述
Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

The only line of each case contains three integers n n n, m m m, k k k ( 2 ≤ n ≤ 1 0 5 2\le n \le 10^5 2n105; KaTeX parse error: Expected 'EOF', got '&' at position 9: 1 \le m &̲lt; k \le n) — the size of the permutation to be constructed and two integers.

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

在这里插入图片描述
Output

For each test case, output the permutation — a set of numbers that satisfies the conditions of the problem. If there are multiple solutions, output any of them.

在这里插入图片描述

解题思路

要构造一个排列使得 ( ∑ i = 1 n f ( i ) − ∑ i = 1 n g ( i ) ) \left(\sum_{i=1}^n f(i) - \sum_{i=1}^n g(i)\right) (i=1nf(i)i=1ng(i)) ,那么我们可以先从大到小输出 k k k n n n之间的数,因为这样的一个过程中 g ( i ) g(i) g(i)的始终为0,且 f ( i ) f(i) f(i)的和最大。

然后输出 m + 1 m + 1 m+1 k − 1 k - 1 k1之间的数,这里的顺序无所谓,因为对于 f ( i ) f(i) f(i) g ( i ) g(i) g(i)都没有影响。
最后从小到大输出 1 1 1 m m m之间的数即可。因为这样的可以使得 g ( i ) g(i) g(i)的和最小,结果就最大。

AC代码

#include<bits/stdc++.h>
#define look(x) cout << #x << " ==  " << x << "\n"
using namespace std;
using i64 = long long;
const int N = 5e5 + 10;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve(){
	int n,m,k;
	cin >> n >> m >> k;
	for(int i = n;i >= k;i --){
		cout << i << " ";
	}	
	for(int i = m + 1;i < k;i ++){
		cout << i << " ";
	}
	for(int i = 1;i <= m;i ++){
		cout << i << " ";
	}
	cout << "\n";
}
int main(){	

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	
	int t = 1;
	cin >> t;

	while(t --){
		solve();
	}
	
	return 0;
}

D. Test of Love

ErnKor is ready to do anything for Julen, even to swim through crocodile-infested swamps. We decided to test this love. ErnKor will have to swim across a river with a width of 1 1 1 meter and a length of n n n meters.

The river is very cold. Therefore, in total (that is, throughout the entire swim from 0 0 0 to n + 1 n+1 n+1) ErnKor can swim in the water for no more than k k k meters. For the sake of humanity, we have added not only crocodiles to the river, but also logs on which he can jump. Our test is as follows:

Initially, ErnKor is on the left bank and needs to reach the right bank. They are located at the 0 0 0 and n + 1 n+1 n+1 meters respectively. The river can be represented as n n n segments, each with a length of 1 1 1 meter. Each segment contains either a log ‘L’, a crocodile ‘C’, or just water ‘W’. ErnKor can move as follows:

  • If he is on the surface (i.e., on the bank or on a log), he can jump forward for no more than m m m ( 1 ≤ m ≤ 10 1 \le m \le 10 1m10) meters (he can jump on the bank, on a log, or in the water).
  • If he is in the water, he can only swim to the next river segment (or to the bank if he is at the n n n-th meter).
  • ErnKor cannot land in a segment with a crocodile in any way.

Determine if ErnKor can reach the right bank.

在这里插入图片描述
Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

The first line of each test case contains three numbers n , m , k n, m, k n,m,k ( 0 ≤ k ≤ 2 ⋅ 1 0 5 0 \le k \le 2 \cdot 10^5 0k2105, 1 ≤ n ≤ 2 ⋅ 1 0 5 1 \le n \le 2 \cdot 10^5 1n2105, 1 ≤ m ≤ 10 1 \le m \le 10 1m10) — the length of the river, the distance ErnKor can jump, and the number of meters ErnKor can swim without freezing.

The second line of each test case contains a string a a a of length n n n. a i a_i ai denotes the object located at the i i i-th meter. ( a i ∈ { a_i \in \{ ai{‘W’,‘C’,‘L’ } \} })

It is guaranteed that the sum of n n n over all test cases does not exceed 2 ⋅ 1 0 5 2 \cdot 10^5 2105.

在这里插入图片描述
Output

For each test case, output “YES” if ErnKor can pass the test, and output “NO” otherwise.

You can output the answer in any case (upper or lower). For example, the strings “yEs”, “yes”, “Yes”, and “YES” will be recognized as positive responses.

在这里插入图片描述

解题思路

考虑dp。 d p [ i ] dp[i] dp[i]表示跳到第i个位置时需要游几米。
判断 d p [ n + 1 ] dp[n + 1] dp[n+1]是否大于k即可。

AC代码

#include<bits/stdc++.h>
#define look(x) cout << #x << " ==  " << x << "\n"
using namespace std;
using i64 = long long;
const int N = 2e5 + 10;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve(){
	int n,m,k;
	cin >> n >> m >> k;
	string s;
	cin >> s;
	s = 'L' + s + 'L';
	vector<int> dp(n + 10);
	for(int i = 1;i <= n + 1;i ++){
		dp[i] = 1e9;
	}	
	//第i个位置时的情况
	for(int i = 1;i <= n + 1;i ++){
		//从第i个位置的前面的位置转移状态
		//既不能大于目前所在位置,也不能大于能够跳跃的最大距离m
		for(int j = 1;j <= min(i,m);j ++){
			//如果只距离一格或者第i - j的位置是原木的话并且第i个位置不能有鳄鱼
			if((j == 1 || s[i - j] == 'L') && s[i] != 'C'){
				dp[i] = min(dp[i],dp[i - j] + (s[i] == 'W'));
			}
		}
	}
	if(dp[n + 1] > k){
		cout << "NO\n";
	}else{
		cout << "YES\n";
	}
}

int main(){	

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	
	int t = 1;
	cin >> t;

	while(t --){
		solve();
	}
	
	return 0;
}

E. Novice’s Mistake

One of the first programming problems by K1o0n looked like this: “Noobish_Monk has n n n ( 1 ≤ n ≤ 100 ) (1 \le n \le 100) (1n100) friends. Each of them gave him a a a ( 1 ≤ a ≤ 10000 ) (1 \le a \le 10000) (1a10000) apples for his birthday. Delighted with such a gift, Noobish_Monk returned b b b ( 1 ≤ b ≤ min ⁡ ( 10000 , a ⋅ n ) ) (1 \le b \le \min(10000, a \cdot n)) (1bmin(10000,an)) apples to his friends. How many apples are left with Noobish_Monk?”

K1o0n wrote a solution, but accidentally considered the value of n n n as a string, so the value of n ⋅ a − b n \cdot a - b nab was calculated differently. Specifically:

  • when multiplying the string n n n by the integer a a a, he will get the string s = n + n + ⋯ + n + n ⏟ a  times s=\underbrace{n + n + \dots + n + n}_{a\ \text{times}} s=a times n+n++n+n
  • when subtracting the integer b b b from the string s s s, the last b b b characters will be removed from it. If b b b is greater than or equal to the length of the string s s s, it will become empty.

Learning about this, ErnKor became interested in how many pairs ( a , b ) (a, b) (a,b) exist for a given n n n, satisfying the constraints of the problem, on which K1o0n’s solution gives the correct answer.

“The solution gives the correct answer” means that it outputs a non-empty string, and this string, when converted to an integer, equals the correct answer, i.e., the value of n ⋅ a − b n \cdot a - b nab.

在这里插入图片描述
Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 100 1 \le t \le 100 1t100) — the number of test cases.

For each test case, a single line of input contains an integer n n n ( 1 ≤ n ≤ 100 1 \le n \le 100 1n100).

It is guaranteed that in all test cases, n n n is distinct.

在这里插入图片描述
Output

For each test case, output the answer in the following format:

In the first line, output the integer x x x — the number of bad tests for the given n n n.

In the next x x x lines, output two integers a i a_i ai and b i b_i bi — such integers that K1o0n’s solution on the test “ n n n a i a_i ai b i b_i bi” gives the correct answer.

在这里插入图片描述

解题思路

要求不同计算方法下的 n ∗ a − b n * a - b nab值相等的 a 、 b a、b ab的情况。
直接考虑字符串计算方式下的 n ∗ a − b n * a - b nab好像不太好求,所以我们观察下数值计算下的 n ∗ a − b n * a - b nab
n < = 100 , a < = 10000 n <= 100,a <= 10000 n<=100,a<=10000,所以我们会发现 n ∗ a n * a na最大为1000000,那么 n ∗ a − b n * a - b nab最大为1000000,因为b为正整数。
所以其实我们只需要考虑字符串下 n ∗ a − b n * a - b nab长度小于7时与数值下 n ∗ a − b n * a - b nab相等的情况即可。
因为数值下的 n ∗ a − b n * a - b nab最多六位数,字符串下的 n ∗ a − b n * a - b nab长度大于6的将无意义。

所以我们只需要枚举 a a a的范围以及 b b b的位数。

AC代码

#include<bits/stdc++.h>
#define look(x) cout << #x << " ==  " << x << "\n"
using namespace std;
using i64 = long long;
const int N = 2e5 + 10;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve(){
	int n;
	cin >> n;
	vector<pair<int,int>> ans;
	string s = to_string(n);
	//枚举a的范围
	for(int i = 1;i <= 10000;i ++){
		//字符串下n * a的长度
		int res = s.size() * i;
		string k = "";
		//取前6位数
		while(k.size() < 7){
			k += s;
		}
//		for(int j = max(1,res- 7);j <= min(10000,res);j ++){
//			
//			if(to_string(n * i - j) == k.substr(0,res - j)){
//				ans.push_back({i,j});
//			}	
//		}
		//枚举b的位数
		for(int j = 1;j <= 6;j ++){
			//res - j其实就是b,因为j是需要保留的位数,那么res - j
			//就是删除的位数,也就是b了。
			//还需要注意的就是所取的位数要小于字符串的长度。
			if(k.substr(0,j) == to_string(n * i - (res - j)) && res > j){
				ans.push_back({i,res - j});
			}
		}
	}
	cout << ans.size() << "\n";
	for(auto [x,y] : ans){
		cout << x << " " << y << "\n";
	}
}

int main(){	

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	
	int t = 1;
	cin >> t;

	while(t --){
		solve();
	}
	
	return 0;
}

F. Valuable Cards

In his favorite cafe Kmes once again wanted to try the herring under a fur coat. Previously, it would not have been difficult for him to do this, but the cafe recently introduced a new purchasing policy.

Now, in order to make a purchase, Kmes needs to solve the following problem: n n n cards with prices for different positions are laid out in front of him, on the i i i-th card there is an integer a i a_i ai, among these prices there is no whole positive integer x x x.

Kmes is asked to divide these cards into the minimum number of bad segments (so that each card belongs to exactly one segment). A segment is considered bad if it is impossible to select a subset of cards with a product equal to x x x. All segments, in which Kmes will divide the cards, must be bad.

Formally, the segment ( l , r ) (l, r) (l,r) is bad if there are no indices KaTeX parse error: Expected 'EOF', got '&' at position 5: i_1 &̲lt; i_2 &lt; \l… such that l ≤ i 1 , i k ≤ r l \le i_1, i_k \le r li1,ikr, and a i 1 ⋅ a i 2 … ⋅ a i k = x a_{i_1} \cdot a_{i_2} \ldots \cdot a_{i_k} = x ai1ai2aik=x.

Help Kmes determine the minimum number of bad segments in order to enjoy his favorite dish.

在这里插入图片描述
Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 3 1 \le t \le 10^3 1t103) — the number of test cases.

The first line of each set of input data gives you 2 2 2 integers n n n and x x x ( 1 ≤ n ≤ 1 0 5 , 2 ≤ x ≤ 1 0 5 1 \le n \le 10^5, 2 \le x \le 10^5 1n105,2x105) — the number of cards and the integer, respectively.

The second line of each set of input data contains n n n integers a i a_i ai ( 1 ≤ a i ≤ 2 ⋅ 1 0 5 , a i ≠ x 1 \le a_i \le 2 \cdot 10^5, a_i \neq x 1ai2105,ai=x) — the prices on the cards.

It is guaranteed that the sum of n n n over all sets of test data does not exceed 1 0 5 10^5 105.

在这里插入图片描述
Output

For each set of input data, output the minimum number of bad segments.

在这里插入图片描述

解题思路

考虑从左往右贪心的去分段。
判断 a [ i ] a[i] a[i]是否是 x x x的因子,如果是话将 x / a [ i ] x / a[i] x/a[i]丢在一个集合里,依次类推,如果这个集合里出现了 1 1 1那么说明现在这个段已经无法成为坏段了,我们需要把现在的 a [ i ] a[i] a[i]给单独分在另一个段里。

AC代码

#include<bits/stdc++.h>
#define look(x) cout << #x << " ==  " << x << "\n"
using namespace std;
using i64 = long long;
const int N = 2e5 + 10;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

void solve(){
	int n,x;
	cin >> n >> x;
	vector<int> a(n + 1);
	for(int i = 1;i <= n;i ++){
		cin >> a[i];
	}
	set<int> st;
	//用set来去重
	st.insert(x);
	int ans = 1;
	for(int i = 1;i <= n;i ++){
		for(auto x : st){
			//丢因子。
			if(x % a[i] == 0){
				st.insert(x / a[i]);
			}
		}
		//存在1说明现在这个数a[i]使得段无法成为坏段
		if(st.find(1) != st.end()){
			//段数加1
			ans ++;
			st.clear();
			st.insert(x);
			st.insert(x / a[i]);
		}
	}
	cout << ans << "\n";
}

int main(){	

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	
	int t = 1;
	cin >> t;

	while(t --){
		solve();
	}
	
	return 0;
}

G. Ultra-Meow

K1o0n gave you an array a a a of length n n n, consisting of numbers 1 , 2 , … , n 1, 2, \ldots, n 1,2,,n. Accept it? Of course! But what to do with it? Of course, calculate MEOW ( a ) \text{MEOW}(a) MEOW(a).

Let MEX ( S , k ) \text{MEX}(S, k) MEX(S,k) be the k k k-th positive (strictly greater than zero) integer in ascending order that is not present in the set S S S. Denote MEOW ( a ) \text{MEOW}(a) MEOW(a) as the sum of MEX ( b , ∣ b ∣ + 1 ) \text{MEX}(b, |b| + 1) MEX(b,b+1), over all distinct subsets b b b of the array a a a.

Examples of MEX ( S , k ) \text{MEX}(S, k) MEX(S,k) values for sets:

  • MEX ( { 3 , 2 } , 1 ) = 1 \text{MEX}(\{3,2\}, 1) = 1 MEX({3,2},1)=1, because 1 1 1 is the first positive integer not present in the set;
  • MEX ( { 4 , 2 , 1 } , 2 ) = 5 \text{MEX}(\{4,2,1\}, 2) = 5 MEX({4,2,1},2)=5, because the first two positive integers not present in the set are 3 3 3 and 5 5 5;
  • MEX ( { } , 4 ) = 4 \text{MEX}(\{\}, 4) = 4 MEX({},4)=4, because there are no numbers in the empty set, so the first 4 4 4 positive integers not present in it are 1 , 2 , 3 , 4 1, 2, 3, 4 1,2,3,4.

在这里插入图片描述
Input

The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104) — the number of test cases.

In a single line of each test case, an integer n n n ( 1 ≤ n ≤ 5000 1 \le n \le 5000 1n5000) is entered, the size of the array of gifted numbers.

It is guaranteed that the sum of n 2 n^2 n2 over all test cases does not exceed 25 ⋅ 1 0 6 25 \cdot 10^6 25106.

在这里插入图片描述
Output

For each test case, output a single number — MEOW ( a ) \text{MEOW}(a) MEOW(a). Since it may be very large, output it modulo 1 0 9 + 7 10^9 + 7 109+7.

在这里插入图片描述

解题思路

待补 待补 待补

AC代码

  • 12
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列题目,其中包括题目E. Kolya and Movie Theatre。 根据题目描述,E. Kolya and Movie Theatre问题要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和题目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E题解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

陈童学哦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值