MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / main

Function main

CSES/Intro/TwoSets.cpp:4–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4int main(){
5 ios_base::sync_with_stdio(false),cin.tie(nullptr);
6
7 int n; cin >> n;
8 int sum = (n*(n+1))/2;
9 if (sum % 2 != 0) {
10 cout << "NO\n";
11 exit(0);
12 }
13 if (n <= 3) {
14 cout << "YES\n";
15 cout <<"2" << '\n';
16 cout << "1 2" << '\n';
17 cout << "1" << '\n';
18 cout << "3" << '\n';
19 exit(0);
20 }
21
22 vector<int> one,second;
23 if (n % 2 == 0) {
24 for(int i = 1; i <= n; ++i) {
25 if (i % 4 == 0 || i % 4 == 1) {
26 one.push_back(i);
27 } else {
28 second.push_back(i);
29 }
30 }
31 } else {
32 one.push_back(1);
33 one.push_back(2);
34 second.push_back(3);
35 for (int i = 1; i <= n - 3; ++i) {
36 if (i % 4 == 0 || i % 4 == 1) {
37 one.push_back(i + 3);
38 } else {
39 second.push_back(i + 3);
40 }
41 }
42 }
43
44 cout << "YES\n";
45 cout << one.size() << '\n';
46 for (auto i : one) cout << i << " ";
47 cout << '\n';
48 cout << second.size() << '\n';
49 for (auto i : second) cout << i << " ";
50 cout << '\n';
51 return 0;
52}
53
54

Callers

nothing calls this directly

Calls 2

push_backMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected