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

2024-06-03 01:44

本文主要是介绍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 longusing 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 longusing 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 longusing 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 题讲解)


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

这篇关于AtCoder Regular Contest 179 (ABC题)视频讲解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1025684

相关文章

springboot家政服务管理平台 LW +PPT+源码+讲解

3系统的可行性研究及需求分析 3.1可行性研究 3.1.1技术可行性分析 经过大学四年的学习,已经掌握了JAVA、Mysql数据库等方面的编程技巧和方法,对于这些技术该有的软硬件配置也是齐全的,能够满足开发的需要。 本家政服务管理平台采用的是Mysql作为数据库,可以绝对地保证用户数据的安全;可以与Mysql数据库进行无缝连接。 所以,家政服务管理平台在技术上是可以实施的。 3.1

百度OCR识别结构结构化处理视频

https://edu.csdn.net/course/detail/10506

基于Java医院药品交易系统详细设计和实现(源码+LW+调试文档+讲解等)

💗博主介绍:✌全网粉丝10W+,CSDN作者、博客专家、全栈领域优质创作者,博客之星、平台优质作者、专注于Java、小程序技术领域和毕业项目实战✌💗 🌟文末获取源码+数据库🌟 感兴趣的可以先收藏起来,还有大家在毕设选题,项目以及论文编写等相关问题都可以给我留言咨询,希望帮助更多的人  Java精品实战案例《600套》 2023-2025年最值得选择的Java毕业设计选题大全:1000个热

数据结构:二叉树详解 c++信息学奥赛基础知识讲解

目录 一、二叉树的定义 二、二叉树的形态 三、二叉树的性质 四、二叉树的存储 五、二叉树的创建与遍历(递归) 六、二叉树实现 创建二叉树 展示二叉树 1、计算数的高度 2、计算数的叶子数量 3、计算数的宽度 4、层次遍历 5、前序遍历 递归写法 非递归写法 6、中序遍历 递归写法 非递归写法 7、后序遍历 递归写法 非递归写法 8、输出根节点到所有叶

RISC-V教学内容及短视频吸引因素

RISC-V 教学内容 在我的认知中,大多数人对RV仍然了解甚少,我想本实习岗位主要面向对 RV 不了解或了解很少的同学,帮助大家更好入门。 因此教学内容为: RISC-V 简要介绍;RISC-V 指令集知识简要讲解,指令集介绍,各个指令集的指令规则及指令运行演示,可以结合模拟器运行结果讲解更为直观;常见 RV 模拟器介绍,分别适用的场景。对于一些简单的 RV 模拟器可以展开讲解安装部署使用

YOLOv9摄像头或视频实时检测

1、下载yolov9的项目 地址:YOLOv9 2、使用下面代码进行检测 import torchimport cv2from models.experimental import attempt_loadfrom utils.general import non_max_suppression, scale_boxesfrom utils.plots import plot_o

google gemini1.5 flash视频图文理解能力初探(一)

市面能够对视频直接进行分析的大模型着实不多,而且很多支持多模态的大模型那效果着实也不好。 从这篇公众号不只是100万上下文,谷歌Gemini 1.5超强功能展示得知,Gemini 1.5可以一次性处理1小时的视频、11小时的音频或100,000行代码,并衍生出更多的数据分析玩法。能力覆盖: 跨模式理解和推理,当给出一部 44 分钟的巴斯特-基顿(Buster Keaton)无声电影时,该模型能准

警惕!推广文章与视频的兼职骗局大揭秘

在互联网时代,我们常常会看到各种各样的推广兼职信息,承诺可以轻松赚钱,特别是在推广文章和视频方面。然而,在这些看似诱人的机会背后,往往隐藏着一些骗局。本文将为大家揭示这些骗局,帮助大家避免上当受骗。 一、骗局特征 1. **高额回报承诺**:骗子常常以高额的回报作为诱饵,声称只要转发文章、分享视频,就能获得丰厚的佣金或收益。然而,这种不切实际的高额回报往往是骗局的开始。 2. **简单操作

视频监控平台:支持交通部行业标准JT/T905协议(即:出租汽车服务管理信息系统)的源代码的函数和功能介绍及分享

目录 一、视频监控平台介绍 (一)概述 (二)视频接入能力介绍 (三)功能介绍 二、JT/T905协议介绍 (一)概述 (二)主要内容 1、设备要求 2、业务功能要求 3、技术功能要求 4、性能要求 5、接口要求 6、设备通信协议与数据格式 三、代码和解释 (一)代码和注释 (二)函数功能说明 1. 头文件保护 2. 包含必要的头文件 3. 引入命名空间std

Codeforces April Fools Day Contest 2014(附官方题解)

Codeforces2014年愚人节的坑题。。。但还是感觉挺好玩的。。。 A. The Great Game time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Two teams mee