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

相关文章

流媒体平台/视频监控/安防视频汇聚EasyCVR播放暂停后视频画面黑屏是什么原因?

视频智能分析/视频监控/安防监控综合管理系统EasyCVR视频汇聚融合平台,是TSINGSEE青犀视频垂直深耕音视频流媒体技术、AI智能技术领域的杰出成果。该平台以其强大的视频处理、汇聚与融合能力,在构建全栈视频监控系统中展现出了独特的优势。视频监控管理系统EasyCVR平台内置了强大的视频解码、转码、压缩等技术,能够处理多种视频流格式,并以多种格式(RTMP、RTSP、HTTP-FLV、WebS

综合安防管理平台LntonAIServer视频监控汇聚抖动检测算法优势

LntonAIServer视频质量诊断功能中的抖动检测是一个专门针对视频稳定性进行分析的功能。抖动通常是指视频帧之间的不必要运动,这种运动可能是由于摄像机的移动、传输中的错误或编解码问题导致的。抖动检测对于确保视频内容的平滑性和观看体验至关重要。 优势 1. 提高图像质量 - 清晰度提升:减少抖动,提高图像的清晰度和细节表现力,使得监控画面更加真实可信。 - 细节增强:在低光条件下,抖

计算机毕业设计 大学志愿填报系统 Java+SpringBoot+Vue 前后端分离 文档报告 代码讲解 安装调试

🍊作者:计算机编程-吉哥 🍊简介:专业从事JavaWeb程序开发,微信小程序开发,定制化项目、 源码、代码讲解、文档撰写、ppt制作。做自己喜欢的事,生活就是快乐的。 🍊心愿:点赞 👍 收藏 ⭐评论 📝 🍅 文末获取源码联系 👇🏻 精彩专栏推荐订阅 👇🏻 不然下次找不到哟~Java毕业设计项目~热门选题推荐《1000套》 目录 1.技术选型 2.开发工具 3.功能

2014 Multi-University Training Contest 8小记

1002 计算几何 最大的速度才可能拥有无限的面积。 最大的速度的点 求凸包, 凸包上的点( 注意不是端点 ) 才拥有无限的面积 注意 :  凸包上如果有重点则不满足。 另外最大的速度为0也不行的。 int cmp(double x){if(fabs(x) < 1e-8) return 0 ;if(x > 0) return 1 ;return -1 ;}struct poin

2014 Multi-University Training Contest 7小记

1003   数学 , 先暴力再解方程。 在b进制下是个2 , 3 位数的 大概是10000进制以上 。这部分解方程 2-10000 直接暴力 typedef long long LL ;LL n ;int ok(int b){LL m = n ;int c ;while(m){c = m % b ;if(c == 3 || c == 4 || c == 5 ||

2014 Multi-University Training Contest 6小记

1003  贪心 对于111...10....000 这样的序列,  a 为1的个数,b为0的个数,易得当 x= a / (a + b) 时 f最小。 讲串分成若干段  1..10..0   ,  1..10..0 ,  要满足x非递减 。  对于 xi > xi+1  这样的合并 即可。 const int maxn = 100008 ;struct Node{int

《x86汇编语言:从实模式到保护模式》视频来了

《x86汇编语言:从实模式到保护模式》视频来了 很多朋友留言,说我的专栏《x86汇编语言:从实模式到保护模式》写得很详细,还有的朋友希望我能写得更细,最好是覆盖全书的所有章节。 毕竟我不是作者,只有作者的解读才是最权威的。 当初我学习这本书的时候,只能靠自己摸索,网上搜不到什么好资源。 如果你正在学这本书或者汇编语言,那你有福气了。 本书作者李忠老师,以此书为蓝本,录制了全套视频。 试

SAM2POINT:以zero-shot且快速的方式将任何 3D 视频分割为视频

摘要 我们介绍 SAM2POINT,这是一种采用 Segment Anything Model 2 (SAM 2) 进行零样本和快速 3D 分割的初步探索。 SAM2POINT 将任何 3D 数据解释为一系列多向视频,并利用 SAM 2 进行 3D 空间分割,无需进一步训练或 2D-3D 投影。 我们的框架支持各种提示类型,包括 3D 点、框和掩模,并且可以泛化到不同的场景,例如 3D 对象、室

树莓派5_opencv笔记27:Opencv录制视频(无声音)

今日继续学习树莓派5 8G:(Raspberry Pi,简称RPi或RasPi)  本人所用树莓派5 装载的系统与版本如下:  版本可用命令 (lsb_release -a) 查询: Opencv 与 python 版本如下: 今天就水一篇文章,用树莓派摄像头,Opencv录制一段视频保存在指定目录... 文章提供测试代码讲解,整体代码贴出、测试效果图 目录 阶段一:录制一段

基于树梅派的视频监控机器人Verybot

最近这段时间做了一个基于树梅派 ( raspberry pi ) 的视频监控机器人平台 Verybot ,现在打算把这个机器人的一些图片、视频、设计思路进行公开,并且希望跟大家一起研究相关的各种问题,下面是两张机器人的照片:         图片1:                   图片2                    这个平台的基本组成是: