AtCoder Regular Contest 179 (ABC题)视频讲解

A - Partition

Problem Statement

You are given integers N N N and K K K.
The cumulative sums of an integer sequence X = ( X 1 , X 2 , … , X N ) X=(X_1,X_2,\dots ,X_N) X=(X1,X2,,XN) of length N N N is defined as a sequence Y = ( Y 0 , Y 1 , … , Y N ) Y=(Y_0,Y_1,\dots ,Y_N) Y=(Y0,Y1,,YN) of length N + 1 N+1 N+1 as follows:
Y 0 = 0 Y_0=0 Y0=0
Y i = ∑ j = 1 i X j   ( i = 1 , 2 , … , N ) Y_i=\displaystyle\sum_{j=1}^{i}X_j\ (i=1,2,\dots ,N) Yi=j=1iXj (i=1,2,,N)
An integer sequence X = ( X 1 , X 2 , … , X N ) X=(X_1,X_2,\dots ,X_N) X=(X1,X2,,XN) of length N N N is called a good sequence if and only if it satisfies the following condition:
Any value in the cumulative sums of X X X that is less than K K K appears before any value that is not less than K K K.
Formally, for the cumulative sums Y Y Y of X X X, for any pair of integers ( i , j ) (i,j) (i,j) such that 0 ≤ i , j ≤ N 0 \le i,j \le N 0i,jN, if KaTeX parse error: Expected 'EOF', got '&' at position 6: (Y_i &̲lt; K and Y j ≥ K ) Y_j \ge K) YjK), then KaTeX parse error: Expected 'EOF', got '&' at position 3: i &̲lt; j.
You are given an integer sequence A = ( A 1 , A 2 , … , A N ) A=(A_1,A_2,\dots ,A_N) A=(A1,A2,,AN) of length N N N. Determine whether the elements of A A A can be rearranged to a good sequence. If so, print one such rearrangement.

Constraints

1 ≤ N ≤ 2 × 1 0 5 1 \leq N \leq 2 \times 10^5 1N2×105
− 1 0 9 ≤ K ≤ 1 0 9 -10^9 \leq K \leq 10^9 109K109
− 1 0 9 ≤ A i ≤ 1 0 9 -10^9 \leq A_i \leq 10^9 109Ai109
All input values are integers.

Input

The input is given from Standard Input in the following format:

N N N K K K
A 1 A_1 A1 A 2 A_2 A2 ⋯ \cdots A N A_N AN

Output

If the elements of A A A can be rearranged to a good sequence, print the rearranged sequence ( A 1 ′ , A 2 ′ , … , A N ′ ) (A^{\prime}_1,A^{\prime}_2,\dots ,A^{\prime}_N) (A1,A2,,AN) in the following format:

Yes
A 1 ′ A^{\prime}_1 A1 A 2 ′ A^{\prime}_2 A2 ⋯ \cdots A N ′ A^{\prime}_N AN

If there are multiple valid rearrangements, any of them is considered correct.
If a good sequence cannot be obtained, print No.

Sample Input 1

4 1
-1 2 -3 4

Sample Output 1

Yes
-3 -1 2 4

If you rearrange A A A to ( − 3 , − 1 , 2 , 4 ) (-3,-1,2,4) (3,1,2,4), the cumulative sums Y Y Y in question will be ( 0 , − 3 , − 4 , − 2 , 2 ) (0,-3,-4,-2,2) (0,3,4,2,2). In this Y Y Y, any value less than 1 1 1 appears before any value not less than 1 1 1.

Sample Input 2

4 -1
1 -2 3 -4

Sample Output 2

No

Sample Input 3

10 1000000000
-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Sample Output 3

Yes
-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 1000000000

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	int n, k, sum = 0;
	cin >> n >> k;

	std::vector<int> a(n);
	for (int i = 0; i < n; i ++)
		cin >> a[i], sum += a[i];

	if (sum < k	&& k <= 0) {
		cout << "No" << endl;
		return 0;
	}

	if (k > 0) sort(a.begin(), a.end());
	else sort(a.begin(), a.end(), greater<int>());
	cout << "Yes" << endl;
	for (int i = 0; i < n; i ++)
		cout << a[i] << " ";
	cout << endl;

	return 0;
}

B - Between B and B

Problem Statement

You are given a sequence ( X 1 , X 2 , … , X M ) (X_1, X_2, \dots, X_M) (X1,X2,,XM) of length M M M consisting of integers between 1 1 1 and M M M, inclusive.
Find the number, modulo 998244353 998244353 998244353, of sequences A = ( A 1 , A 2 , … , A N ) A = (A_1, A_2, \dots, A_N) A=(A1,A2,,AN) of length N N N consisting of integers between 1 1 1 and M M M, inclusive, that satisfy the following condition:
For each B = 1 , 2 , … , M B = 1, 2, \dots, M B=1,2,,M, the value X B X_B XB exists between any two different occurrences of B B B in A A A (including both ends).
More formally, for each B = 1 , 2 , … , M B = 1, 2, \dots, M B=1,2,,M, the following condition must hold:
For every pair of integers ( l , r ) (l, r) (l,r) such that KaTeX parse error: Expected 'EOF', got '&' at position 10: 1 \leq l &̲lt; r \leq N and A l = A r = B A_l = A_r = B Al=Ar=B, there exists an integer m m m ( l ≤ m ≤ r l \leq m \leq r lmr) such that A m = X B A_m = X_B Am=XB.

Constraints

1 ≤ M ≤ 10 1 \leq M \leq 10 1M10
1 ≤ N ≤ 1 0 4 1 \leq N \leq 10^4 1N104
1 ≤ X i ≤ M 1 \leq X_i \leq M 1XiM
All input values are integers.

Input

The input is given from Standard Input in the following format:

M M M N N N
X 1 X_1 X1 X 2 X_2 X2 ⋯ \cdots X M X_M XM

Output

Print the answer.

Sample Input 1

3 4
2 1 2

Sample Output 1

14

Here are examples of sequences A A A that satisfy the condition:
( 1 , 3 , 2 , 3 ) (1, 3, 2, 3) (1,3,2,3)
( 2 , 1 , 2 , 1 ) (2, 1, 2, 1) (2,1,2,1)
( 3 , 2 , 1 , 3 ) (3, 2, 1, 3) (3,2,1,3)
Here are non-examples:
( 1 , 3 , 1 , 3 ) (1, 3, 1, 3) (1,3,1,3)
There is no X 3 = 2 X_3 = 2 X3=2 between the 3 3 3s.
( 2 , 2 , 1 , 3 ) (2, 2, 1, 3) (2,2,1,3)
There is no X 2 = 1 X_2 = 1 X2=1 between the 2 2 2s.

Sample Input 2

4 8
1 2 3 4

Sample Output 2

65536

All sequences of length 8 8 8 consisting of integers between 1 1 1 and 4 4 4 satisfy the condition.
Note that when X B = B X_B = B XB=B, there is always a B B B between two different occurrences of B B B.

Sample Input 3

4 9
2 3 4 1

Sample Output 3

628

Solution

具体见文末视频。

Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

const int N = 1e4 + 10, M = 11, mod = 998244353;

int n, m;
int a[M], f[N][1 << M], mask[M];

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	cin >> m >> n;

	for (int i = 1; i <= m; i ++)
		cin >> a[i], mask[a[i]] |= 1ll << i - 1;

	f[0][(1 << m) - 1] = 1;
	for (int i = 0; i < n; i ++)
		for (int j = 1; j <= m; j ++)
			for (int k = 0; k < 1 << m; k ++)
				if ((k >> j - 1) & 1)
					f[i + 1][(k ^ (1 << j - 1)) | mask[j]] = (f[i + 1][(k ^ (1 << j - 1)) | mask[j]] + f[i][k]) % mod;

	int res = 0;
	for (int i = 0; i < 1 << m; i ++)
		res = (res + f[n][i]) % mod;

	cout << res << endl;

	return 0;
}

C - Beware of Overflow

Problem Statement

This is an interactive problem (where your program interacts with the judge via input and output).
You are given a positive integer N N N.
The judge has a hidden positive integer R R R and N N N integers A 1 , A 2 , … , A N A_1, A_2, \dots, A_N A1,A2,,AN. It is guaranteed that ∣ A i ∣ ≤ R |A_i|\le R AiR and ∣ ∑ i = 1 N A i ∣ ≤ R \left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R i=1NAi R.
There is a blackboard on which you can write integers with absolute values not exceeding R R R. Initially, the blackboard is empty.
The judge has written the values A 1 , A 2 , … , A N A_1, A_2, \dots, A_N A1,A2,,AN on the blackboard in this order. Your task is to make the blackboard contain only one value ∑ i = 1 N A i \displaystyle\sum_{i=1}^{N}A_i i=1NAi.
You cannot learn the values of R R R and A i A_i Ai directly, but you can interact with the judge up to 25000 25000 25000 times.
For a positive integer i i i, let X i X_i Xi be the i i i-th integer written on the blackboard. Specifically, X i = A i X_i = A_i Xi=Ai for i = 1 , 2 , … , N i=1,2,\dots,N i=1,2,,N.
In one interaction, you can specify two distinct positive integers i i i and j j j and choose one of the following actions:
Perform addition. The judge will erase X i X_i Xi and X j X_j Xj from the blackboard and write X i + X j X_i + X_j Xi+Xj on the blackboard.
∣ X i + X j ∣ ≤ R |X_i + X_j| \leq R Xi+XjR must hold.
Perform comparison. The judge will tell you whether KaTeX parse error: Expected 'EOF', got '&' at position 5: X_i &̲lt; X_j is true or false.
Here, at the beginning of each interaction, the i i i-th and j j j-th integers written on the blackboard must not have been erased.
Perform the interactions appropriately so that after all interactions, the blackboard contains only one value ∑ i = 1 N A i \displaystyle\sum_{i=1}^{N}A_i i=1NAi.
The values of R R R and A i A_i Ai are determined before the start of the conversation between your program and the judge.

Constraints

2 ≤ N ≤ 1000 2 \leq N \leq 1000 2N1000
1 ≤ R ≤ 1 0 9 1 \leq R \leq 10^9 1R109
∣ A i ∣ ≤ R |A_i| \leq R AiR
∣ ∑ i = 1 N A i ∣ ≤ R \left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R i=1NAi R
N N N, R R R, and A i A_i Ai are integers.

Input and Output

This is an interactive problem (where your program interacts with the judge via input and output).
First, read N N N from Standard Input.

N N N

Next, repeat the interactions until the blackboard contains only one value ∑ i = 1 N A i \displaystyle\sum_{i=1}^{N}A_i i=1NAi.
When performing addition, make an output in the following format to Standard Output. Append a newline at the end. Here, i i i and j j j are distinct positive integers.

  • i i i j j j

The response from the judge will be given from Standard Input in the following format:

P P P

Here, P P P is an integer:
If P ≥ N + 1 P \geq N + 1 PN+1, it means that the value X i + X j X_i + X_j Xi+Xj has been written on the blackboard, and it is the P P P-th integer written.
If P = − 1 P = -1 P=1, it means that i i i and j j j do not satisfy the constraints, or the number of interactions has exceeded 25000 25000 25000.
When performing comparison, make an output in the following format to Standard Output. Append a newline at the end. Here, i i i and j j j are distinct positive integers.

? i i i j j j

The response from the judge will be given from Standard Input in the following format:

Q Q Q

Here, Q Q Q is an integer:
If Q = 1 Q = 1 Q=1, it means that KaTeX parse error: Expected 'EOF', got '&' at position 5: X_i &̲lt; X_j is true.
If Q = 0 Q = 0 Q=0, it means that KaTeX parse error: Expected 'EOF', got '&' at position 5: X_i &̲lt; X_j is false.
If Q = − 1 Q = -1 Q=1, it means that i i i and j j j do not satisfy the constraints, or the number of interactions has exceeded 25000 25000 25000.
For both types of interactions, if the judge’s response is − 1 -1 1, your program is already considered incorrect. In this case, terminate your program immediately.
When the blackboard contains only one value ∑ i = 1 N A i \displaystyle\sum_{i=1}^{N}A_i i=1NAi, report this to the judge in the following format. This does not count towards the number of interactions. Then, terminate your program immediately.

!

If you make an output in a format that does not match any of the above, -1 will be given from Standard Input.

-1

In this case, your program is already considered incorrect. Terminate your program immediately.

Notes

For each output, append a newline at the end and flush Standard Output. Otherwise, the verdict may be TLE.
Terminate your program immediately after outputting the result (or receiving -1). Otherwise, the verdict will be indeterminate.
Extra newlines will be considered as malformed output.

Sample Input and Output

Here is a possible conversation with N = 3 , R = 10 , A 1 = − 1 , A 2 = 10 , A 3 = 1 N=3, R=10, A_1=-1, A_2=10, A_3=1 N=3,R=10,A1=1,A2=10,A3=1.

InputOutputExplanation
3First, the integer $N$ is given.
? 1 2Perform a comparison.
1The judge returns $1$ because $X_1\lt X_2\ (-1\lt 10)$.
+ 1 3Perform an addition.
4The judge erases $X_1 = -1$ and $X_3 = 1$ from the blackboard and writes $X_1 + X_3 = 0$. This is the fourth integer written.
+ 2 4Perform an addition.
5The judge erases $X_2 = 10$ and $X_4 = 0$ from the blackboard and writes $X_2 + X_4 = 10$. This is the fifth integer written.
!The blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$, so report this to the judge.

Solution

具体见文末视频。


Code

#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef long long LL;

bool cmp(int a, int b) {
	cout << "? " << a << " " << b << endl;
	int ok;
	cin >> ok;
	return ok;
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);

	int n;
	cin >> n;

	std::vector<int> id;
	for (int i = 1; i <= n; i ++)
		id.push_back(i);
	sort(id.begin(), id.end(), cmp);
	while (n > 1) {
		cout << "+ " << id[0] << " " << id.back() << endl;
		int p;
		cin >> p;
		id.erase(id.begin()), id.pop_back();
		n --;
		if (n == 1) break;
		int l = 0, r = id.size() - 1;
		while (l < r) {
			int mid = l + r >> 1;
			if (cmp(p, id[mid])) r = mid;
			else l = mid + 1;
		}
		if (!cmp(p, id[r])) r ++;
		id.insert(id.begin() + r, p);
	}

	cout << "!\n";

	return 0;
}

视频题解

AtCoder Regular Contest 179(A ~ C 题讲解)


最后祝大家早日在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/672797.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

java收徒、java面试辅导、java辅导、java就业辅导

&#x1f497;博主介绍&#xff1a;✌全网粉丝1W,CSDN作者、博客专家、全栈领域优质创作者&#xff0c;博客之星、平台优质作者、专注于Java、小程序技术领域和毕业项目实战✌&#x1f497; &#x1f31f;文末获取源码数据库&#x1f31f; 感兴趣的可以先收藏起来&#xff0c;还…

本机安装深度学习库cuda11.8,cudnn8.6和tensorRT8.5

https://blog.csdn.net/qq_46107892/article/details/131453019 首先是安装cuda11.8 wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pinsudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600wg…

Go 1.23新特性前瞻

2024年5月22日&#xff0c;Go 1.23版本[1]功能特性正式冻结&#xff0c;后续将只改bug&#xff0c;不增加新feature。 对Go团队来说&#xff0c;这意味着开始了Go 1.23rc1的冲刺&#xff0c;对我们普通Gopher而言&#xff0c;这意味着是时候对Go 1.23新增的功能做一些前瞻了&am…

面试(五)

目录 1. 知道大顶堆小顶端吗&#xff0c;代码怎么区分大顶端小顶端 2. 计算机中栈地址与内存地址增长方向相反吗&#xff1f; 3. %p和%d输出指针地址 4. 为什么定义第二个变量时候&#xff0c;地址反而减了 5. 12&#xff0c;32&#xff0c;64位中数据的占字节&#xff1f;…

DIYP对接骆驼后台IPTV管理,退出菜单中显示用户名已经网络信息,MAC,剩余天数,套餐名称等

演示&#xff1a;https://url03.ctfile.com/f/1779803-1042599473-4dc000?p8976 (访问密码: 8976) 后台加上EPG&#xff0c;增加一些播放源的动态端口替换。 前台app上&#xff0c;退出菜单中显示用户名已经网络信息&#xff0c;MAC&#xff0c;剩余天数&#xff0c;套餐名称…

网络原理——http/https ---http(2)

http(接上一篇文章) 认识请求报头"header" header里面的键值对,都是标准规定的内容,很多,我们主要是认识一些关键的 host 表示对应的服务器主机的IP / 域名 实际上,这两个通常来说是一样的 但是有些时候不一样 当我们通过代码构造http请求,url里面写的以Ip地址的…

企业使用人工智能创建营销内容的8种实践

企业使用人工智能创建营销内容的8种实践 原文作者&#xff1a;朱丽叶约翰 编辑&#xff1a;数字化营销工兵 内容营销人员是第一批从“只玩人工智能”转变为“在日常工作中使用人工智能”的人。为了了解人工智能内容创作的哪些部分影响最大&#xff0c;我询问了其他营销人员如…

论文阅读笔记(十一)——BioInformatics Agent (BIA)

论文阅读笔记(十一)——BioInformatics Agent (BIA): Unleashing the Power of Large Language Models to Reshape Bioinformatics Workflow 目录 论文阅读笔记(十一)——BioInformatics Agent (BIA): Unleashing the Power of Large Language Models to Reshape Bioinformatic…

2023年全国职业院校技能大赛(高职组)“云计算应用”赛项赛卷7(私有云)

#需要资源&#xff08;软件包及镜像&#xff09;或有问题的&#xff0c;可私聊博主&#xff01;&#xff01;&#xff01; #需要资源&#xff08;软件包及镜像&#xff09;或有问题的&#xff0c;可私聊博主&#xff01;&#xff01;&#xff01; #需要资源&#xff08;软件包…

IP协议1.0

基本概念&#xff1a; • 主机: 配有IP地址, 但是不进⾏路由控制的设备; • 路由器: 即配有IP地址, ⼜能进⾏路由控制; • 节点: 主机和路由器的统称; IP协议的报头 • 4位版本号(version): 指定IP协议的版本, 对于IPv4来说, 就是4. • 4位头部⻓度(header length): IP头部的⻓…

微博增强-tampermonkey脚本实现网页管理悄悄关注

不是很明白微博为什么不出个x的列表功能&#xff0c;毕竟现在信息洪流&#xff0c;有些东西只是要看要了解&#xff0c;但不希望天天在首页轰炸眼睛&#xff0c;扰乱心智。 这个tampermonkey脚本适配了pc web和手机pwa版本&#xff08;weibo.com/m.weibo.cn&#xff09;,解决了…

【LeetCode算法】第104题:二叉树的最大深度

目录 一、题目描述 二、初次解答 三、官方解法 四、总结 一、题目描述 二、初次解答 1. 思路&#xff1a;二叉树的先序遍历。首先判断根节点是否是空&#xff0c;其次判断根节点是否是叶子节点&#xff0c;再者递归获取左子树的深度、右子树的深度&#xff0c;最后返回左子…

设计模式(十二)行为型模式---模板方法模式(template)

文章目录 模板方法模式结构优缺点UML图具体实现UML图代码实现 模板方法模式 模板方法模式&#xff08;Template Method&#xff09;是一种基于继承实现的设计模式&#xff0c;主要思想是&#xff1a;将定义的算法抽象成一组步骤&#xff0c;在抽象类中定义算法的骨架&#xff…

HOW - BFF 服务实践系列(一)

目录 一、BFF 介绍1.1 BFF 的概念1.2 为什么需要 BFF1.3 举例说明 二、适用于Web前端的BFF应该提供哪些能力2.1 接口聚合&#xff08;重要&#xff09;2.2 简化和优化的API2.3 安全和身份验证&#xff08;重要&#xff09;2.4 缓存机制2.5 错误处理和重试机制2.6 数据格式转换2…

(ISPRS,2023)RS-CLIP: 基于对比视觉-语言监督的zero-shot遥感场景分类

文章目录 相关资料摘要引言方法CLIP回顾伪标签生成课程学习策略 实验数据集不同文本提示失败案例分析课程学习zero-shot分类 相关资料 论文&#xff1a;RS-CLIP: Zero shot remote sensing scene classification via contrastive vision-language supervision 摘要 零样本遥…

未来已来:Spring Boot引领数据库智能化革命

深入探讨了Spring Boot如何与现代数据库技术相结合&#xff0c;预测并塑造未来的数据访问趋势。本书不仅涵盖了Spring Data JPA的使用技巧&#xff0c;还介绍了云原生数据库的概念&#xff0c;微服务架构下的数据访问策略&#xff0c;以及AI在数据访问层的创新应用。旨在帮助开…

视频搬运的素材网站有哪些?打包好的视频素材在哪找?

短视频创作的朋友们&#xff0c;欢迎进入这个充满创意的世界&#xff01;如果你曾为找不到合适的素材而苦恼&#xff0c;那么今天就让我为你介绍几个能够快速丰富你视频内容的素材平台。无论是为了搬运视频还是寻找灵感&#xff0c;下面这些网站都将是你的强力助手。特别地&…

lammps金刚石三棱锥刀具建模

大家好&#xff0c;我是小马老师。 本文介绍lammps三棱锥刀具建模方法。 lammps切削模拟的刀具形状有很多&#xff0c;如球形、锐角、钝角、三棱锥等刀具。 球形、锐角、钝角等刀具建模已经在公众号发过&#xff0c;本文介绍三棱锥的建模。 形状如下图所示&#xff1a; 主要原…

探索 Vue Devtools 4.0 的新世界!

大家好&#xff0c;我是前端宝哥。Vue Devtools 4.0 版本带来了一系列激动人心的新特性和改进&#xff0c;让我们一起来探索这些更新亮点&#xff01; 宝哥省流版&#xff1a; &#x1f6e0; 直接编辑组件数据&#xff0c;实时预览变更效果。⚙️ 快速编辑功能&#xff0c;一键…

使用python实现超市购物系统(一个小例子)

可以增加其他功能&#xff0c;这里就展示一个小的例子~