0%

[題解]CSES 1092 Two Sets

Two Sets

題目連結

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
#define int long long
#define N 1000005
using namespace std;
int n;

void solve(){
int total = n*(n+1)/2,sum = 0,cnt = 0;
bool vis[N];memset(vis,0,sizeof(vis));
if(total & 1){
cout<<"NO"<<"\n";
return;
}
cout<<"YES"<<"\n";
for(int i=n;i>=1;i--){
int next = sum + i;
if(next <= total/2){
sum += i;
cnt++;
vis[i] = 1;
}
}
cout<<cnt<<"\n";
for(int i=1;i<=n;i++){
if(vis[i])cout<<i<<" ";
}
cout<<"\n"<<n - cnt<<"\n";
for(int i=1;i<=n;i++){
if(!vis[i])cout<<i<<" ";
}
cout<<"\n";
}

signed main(){
cin>>n;
solve();
return 0;
}