第一行一个表示序列长度,接下来一行
个数,第
个为
,表示序列中的第
个数。
。
一行一个字符串。"YES"表示可能重新排列这个序列使得所有长度小于等于的子区间和不等于
,反之则输出“NO”。输出不含引号。
6 34 1345 -3542 -1423 4213 1
YES
不变即可。
4 1 1 -1 1
NO
无论怎样排列,总和至少
个
相邻,所以总存在一个和为
的长度为
的子段。
5 1 5 -1 -5 0
NO
的存在使得总有一个长度为
的子段和为
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
cin.tie(0)->sync_with_stdio(0);
ll n;cin >> n;
ll qc=n;//不严谨的去重
ll mi=2e9+1,ma=-2e9-1;
for(ll i=0;i<n;i++)
{
ll num;cin >> num;
if(num==0)//有0就不可以
{
cout << "NO";
return 0;
}
if(num==mi||num==ma) qc--;//去重
if(num>ma)
{
ma=num;
}
if(num<mi)
{
mi=num;
}
}
if(qc==2&&ma+mi==0)//如果只有两个数且为相反数
{
cout << "NO";
}
else cout << "YES";
}
/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣤⡀⣀⣠⣤⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⡀⢀⣴⣾⣷⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣷⣾⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⠿⠛⠛⠉⠉⠉⠉⠉⠉⠛⠻⠿⣿⣿⣿⣿⣿⣶⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢠⣾⣿⣿⣿⡿⠿⠛⠉⠉⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠙⠿⣿⣿⣿⣷⣄⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣀⣿⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⣰⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠿⣿⣿⣿⡄⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣾⣿⣿⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣶⣄⠀⠀⠀⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣻⣿⣿⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⢹⣿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣿⠁⠈⢢⡀⠀⠀⠀⢸⡇⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⡟⠒⢦⡀⠀⠀⠀
⠀⠀⣠⣤⣤⣼⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⡇⠀⠀⠀⠉⢢⣄⠀⠀⢿⠊⠳⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣷⡄⠀⢷⠀⠀⠀
⠀⢰⠇⠀⣰⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⠀⠀⡌⣹⠗⠦⣬⣇⠀⠉⢢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⡀⢸⡄⠀⠀
⠀⡟⠀⣼⣯⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⣆⢹⡀⠀⠀⠀⠉⠁⠀⠀⢀⣀⡁⠀⠀⠉⠳⢴⡆⠀⠀⠀⠀⠀⠀⢹⣧⠈⡇⠀⠀
⠀⡇⠀⠀⢻⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣾⠻⠉⠛⠂⠀⠀⠀⠀⠀⠀⠻⠿⣿⣿⣿⣶⣦⡀⠛⣇⠀⠀⠀⠀⠀⣈⣿⠀⡇⠀⠀
⢸⡇⠀⠀⢠⣿⣷⣦⣀⡸⣷⣦⣶⡂⠉⠉⠉⢁⣤⣶⡶⠀⠀⠀⣀⣀⡴⠀⠀⠀⠀⠀⠀⠈⠉⠉⠁⠀⡟⢀⣴⣟⣰⣾⣿⣏⣠⠇⠀⠀
⠈⡇⠀⠀⢸⣿⠁⠉⣿⠛⠛⠃⡇⠀⠀⢠⣶⣿⡿⠛⠁⠀⠀⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠼⢿⠟⠿⢿⡏⠀⠘⣿⡀⠀⠀⠀
⠀⢷⣀⣀⣿⠇⠀⠀⢿⡇⠀⢀⢱⡀⠀⠛⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠀⠀⢸⠇⠀⠀⢹⣿⣄⠀⠀
⠀⠀⣉⣿⡏⠀⠀⠀⠀⠀⠀⢸⣇⣳⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⣿⠃⠀⠀⠀⠀⠀⠀⣿⠈⢧⠀
⠀⠘⣿⣿⠁⠀⠀⠀⠀⠀⠀⠘⣿⡛⣶⠀⠀⣠⠔⠒⠛⠒⠦⡀⠀⠀⠀⠀⣠⡤⠶⠤⢤⣀⠀⠀⠀⢀⣏⡄⠀⠀⠀⠀⠀⡀⣿⡆⠈⣧
⣠⡾⠛⣿⣿⣧⠀⠀⠀⠀⢸⣿⠾⢿⡿⠀⣰⠃⠀⠀⠀⠀⠀⢹⡄⠀⠀⡼⠁⠀⠀⠀⠀⠈⠙⣦⠀⢸⣿⡇⣾⣣⡀⠀⢰⣿⣿⣿⣤⠾
⡟⠀⠀⠻⣿⡟⢷⡄⣤⡀⠈⣿⡀⣸⠇⠀⠏⠀⠀⠀⠀⠀⠀⠀⡇⠀⠀⡇⢀⡀⠀⠀⠀⠀⢀⡟⠀⠀⠋⣿⣿⣿⡇⣠⣿⠿⠛⢷⡀⠀
⠀⠀⠀⠀⣿⣇⣨⣿⣿⣿⣦⣽⣷⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⠃⠀⠙⠢⠤⠤⠴⢾⠀⠀⠀⠀⢸⣷⣿⣿⠟⠁⠀⠀⠈⣧⠀
⠀⠀⠀⠀⠈⠉⠉⠁⠈⠉⠈⢉⣿⡁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⣿⠀
*/ #include <iostream>
#include<bits/stdc++.h>
#include <vector>
using namespace std;
#define int long long
//1 -1 -1
signed main(){
int n;cin>>n;
vector<int> a(n+1);
map<int,int> mp;
for(int i=1;i<=n;i++){
cin>>a[i];
mp[a[i]]++;
if(a[i]==0){
cout<<"NO";
return 0;
}
}
for(int i=1;i<=n;i++){
if(mp[a[i]]+mp[-a[i]]==n&&mp[a[i]]&&mp[-a[i]]){
cout<<"NO";
return 0;
}
}
cout<<"YES";
return 0;
} #include <stdio.h>
int main() {
long int a, b,d,e,f,g,h,i,q;
long int c[500000];
scanf("%ld",&a);
d=a;
for (a=a,b=0; a>0;a--) {
scanf("%ld",&c[b]);
b=b+1;
}
for (d=d,e=0; d>0;d-- ) {
for (g=d,f=0; g>0;g-- ) {
h=c[e];
i=c[f];
if (e==f) {break;
}else if
(h+i==0){
q=1;
printf("NO");
break;
}
f=f+1;
}
if (q==1) {
break;
}
else if (d==1) {printf("YES");
break;
}
e=e+1;
}
return 0;
} 请问为什么调试的结果没问题,但是保存提交后却报错没有输出内容 #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main ()
{
int n;
cin>>n;
vector <ll> a(n, 0);
for (int i = 0;i < n;i++) {
cin>>a[i];
if (a[i] == 0) {
cout<<"NO";
return 0;
}
}
sort (a.begin(), a.end());
//for (auto num : a) cout<<num<<" ";
for (int i = 0;i < n;i++) {
if (a[i] > 0) {
if (a[i - 1] + a[i] == 0) {
if (a[i - 1] + a[n - 1] == 0) cout<<"NO";
else cout<<"YES";
} else cout<<"YES";
break;
}
}
return 0;
} while (*buf++ != '\n') {}
bool positive = false; // 存在正数
bool negative = false; // 存在负数
bool different = false; // (剔除负号)存在不同的值
if (*buf == '0') { // 遇到0直接结束
puts("NO");
return 0;
} else if (*buf == '-') {
negative = true; // 负数
buf++; // 剔除负号
} else {
positive = true; // 正数
}
// 从start到end的字符用来比对
char* start = buf;
while (*buf >= '0') buf++;
char* end = buf;
while (*buf++ == ' ') { // 以空格分割,直到换行结束
if (different) { // 前面已找到不同,无需读取数字
if (*buf++ == '0') { // 遇到0直接结束
puts("NO");
return 0;
}
// 从第2个字符起,跳过所有数字
while (*buf >= '0') buf++;
} else { // 前面未找到不同,比对数字
if (*buf == '0') { // 遇到0直接结束
puts("NO");
return 0;
} else if (*buf == '-') {
negative = true; // 负数
buf++; // 剔除负号
} else {
positive = true; // 正数
}
for (char* ch = start; ch != end; ch++) {
if (*buf < '0') {
different = true; // 比预期的短
break;
} else if (*buf++ != *ch) {
different = true; // 找到不同字符
while (*buf >= '0') buf++;
}
}
if (*buf >= '0') {
different = true; // 比预期的长
while (*buf >= '0') buf++;
}
}
}
// 有正数有负数且绝对值全部相同,则输出NO,否则,输出YES
puts((!different && (positive & negative)) ? "NO" : "YES");
return 0;