题解归档 - cf2220A
本文最后由方少年更新于2026 年 6 月 28 日,已超过0天没有更新。如果文章内容或图片资源失效,请留言反馈,将会及时处理,谢谢!
题解归档 - cf2220A
本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。
- 本地编号:
cf2220A - 本地来源:
problems/cf2220A/idea.md - 题目链接:https://codeforces.com/contest/2220/problem/A
- 原始标题:cf2220A - Blocked
思路
cf2220A - Blocked
Pattern
All numbers are positive. If two equal values exist, whichever copy appears
later is blocked by the earlier equal copy, so the answer is impossible.
If all values are distinct, sort them in decreasing order. For any position,
all previous values are strictly larger than the current value, and every
non-empty subset sum of previous values is therefore larger than the current
value. Hence no position is blocked.
Algorithm
- If any duplicate exists, print
-1. - Otherwise print the array in descending order.
Checks
python tools/math_reasoning_search.py --problem cf2220A -n 5- required
precheck done.
代码
来源:problems/cf2220A/solution.cpp
/* Author: likely
* Time: 2026-06-08 00:05:00
**/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll s[205],cnt[105];
int main(){
ll t,n,i,zc;
cin>>t;
while(t--){
cin>>n;
zc=0;
for(i=1;i<=100;i++) cnt[i]=0;
for(i=1;i<=n;i++){
cin>>s[i];
if(cnt[s[i]]) zc=1;
cnt[s[i]]++;
}
if(zc){
cout<<"-1\n";
continue;
}
sort(s+1,s+n+1,greater<ll>());
for(i=1;i<=n;i++){
if(i>1) cout<<" ";
cout<<s[i];
}
cout<<"\n";
}
return 0;
}
~ ~ The End ~ ~
文章标题:题解归档 - cf2220A
文章链接:https://www.fangshaonian.cn/archives/211/
最后编辑:2026 年 6 月 28 日 19:04 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)