CodeTON Round 3 (Div. 1 + Div. 2, Rated, Prizes!)1750

https://codeforces.com/contest/1750/
新手第二把solved2 rating+254

A

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
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
int n;
cin >> n;
vector<int> a(n + 1);
// bool flag = true;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (a[1] == 1)
cout << "Yes" << endl;
else
cout << "No" << endl;
return;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}

B

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
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;

void solve() {
int a;
int n;
cin >> n;
string s;
cin >> s;
int ans0 = 0, ans1 = 0;
int cnt0 = 0, cnt1 = 0;
int s0 = 0, s1 = 0;
// 记录连续0和1的个数
for (auto a : s) {
if (a == '0') {
ans0++;
cnt0++;
cnt1 = 0;
} else {
ans1++;
cnt1++;
cnt0 = 0;
}
s0 = max(s0, cnt0);
s1 = max(s1, cnt1);
}
// 0 和 1 都有
int r1 = ans0 * ans1;
// 只有0
int r2 = s0 * s0;
// 只有1
int r3 = s1 * s1;
cout << max({r1, r2, r3}) << endl;
return;
}

signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}

C

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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define x first
#define y second
using namespace std;

typedef pair<int, int> PII;

void solve() {
int n;
cin >> n;
string s1, s2;
cin >> s1 >> s2;
s1 = "?" + s1;
s2 = "?" + s2;
// 记录不相同的个数
int cnt = 0;
// 记录0的个数, 1的个数
int cnt1 = 0, cnt2 = 0;
for (int i = 1; i <= n; i++) {
if (s1[i] == s2[i]) {
if (s1[i] == '0')
cnt1++;
else
cnt2++;
} else
cnt++;
}
// 如果不是全相等或者全相反,就一定不可以
if (cnt != 0 && cnt != n) {
cout << "NO" << endl;
return;
}
// 如果全是0,就不用判断了,一定可以
if (cnt1 == n) {
cout << "YES" << endl;
cout << 0 << endl;
return;
}
// 如果全是1,就不用判断了,一定可以
if (cnt2 == n) {
cout << "YES" << endl;
cout << 2 << endl;
cout << 1 << " " << 1 << endl;
cout << 2 << " " << n << endl;
return;
}

// 一般情况
vector<PII> ans;
// 记录目前操作了多少次
int cur = 0;

// 如果是 Case1,就不管
// 如果是 Case2,就要多操作一下转换为 Case1
if (cnt) cur++;

// 对于Case1 操作每一个 1
for (int i = 1; i <= n; i++) {
if (s1[i] == '1') {
ans.push_back({i, i});
cur++;
}
}
// 如果是1的个数是单数的,最后会剩下一个11对,也进行一下操作
if (cur % 2 == 1) {
ans.push_back({1, 1});
ans.push_back({2, n});
ans.push_back({1, n});
}
cout << "YES" << endl;
cout << ans.size() << endl;
for (auto it : ans) cout << it.first << " " << it.second << endl;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(nullptr);
int _ = 1;
cin >> _;
while (_--) {
solve();
}
return 0;
}