Codeforces Round 803 (Div. 2)

发布时间 2023-12-10 18:43:30作者: 加固文明幻景

基本情况

A题秒了。

B题经典+2。(经典不开longlong)

C题读错题,没得思路。

B. Rising Sand

Problem - B - Codeforces

思路好想,分类讨论找规律就行。

这里还是要强调一下认真分析数据

Input

The second line of each test case contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (\(1 \le a_i \le 10^9\)) — the sizes of the piles.

\(a_i\) 已经接近 int 的边界了,然后我还有一个这个语句:

if (a[i] > a[i - 1] + a[i + 1])

两个 \(a_i\) 相加是有可能爆 int 的!改成 long long 就AC了。

C. 3SUM Closure

Problem - C - Codeforces

纯暴力肯定是T,然后我又想不到啥结论。

而且,我读了个假题!

题目是所有三元组满足才是"YES"。我读成只要有三元组满足就 "YES"。

思路

既然要求所有三元组,那就有方向了。

因为最大三个值中必定不能全正,同理最小三个值中必定不能全负,而且若干个 \(0\) 与两个 \(0\) 是等价的,直接把多余的去掉。

之后可能符合条件的数列最多只剩下 \(6\) 个数,然后暴力判断。

只能说,读题不认真,思路根本不可能对。

代码

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#define N 200005

using namespace std;

int T,n,tot;
int a[N],b[N];
map <int,bool> mp;
int cnt_1,cnt_2,fl_0;
bool fl;

int main(){
	scanf("%d",&T);
	
	while(T--){
		mp.clear();
		tot=0;
		fl=0;
		fl_0=cnt_1=cnt_2=0;
		scanf("%d",&n);
		
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			
			if(a[i]>0) ++cnt_1;
			else if(a[i]<0) ++cnt_2;
			else if(a[i]==0) fl_0=1; 
		} 
			
		if(cnt_1+fl_0>=3 || cnt_2+fl_0>=3){
			printf("NO\n");
			continue;
		} 
			
		sort(a+1,a+1+n);
		
		for(int i=1;i<=n;i++){
			if(!b[tot] && !a[i]) continue;
			b[++tot]=a[i];
			mp[b[tot]]=1;
		} 
		
		for(int i=1;i<=tot;i++)
			for(int j=i+1;j<=tot;j++)
				for(int k=j+1;k<=tot;k++)
					if(!mp[b[i]+b[j]+b[k]])
						fl=1;
		printf(fl?"NO\n":"YES\n");
	}
	
	return 0;
}