Educational Codeforces Round 123

A:Doors and Keys

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
#include <iostream>
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
using namespace std;

int main()
{
int t;
cin >> t;
while(t--) {
string s;
map<char, bool> vis;
cin >> s;
int flag = 0;
for (int i = 0; i < s.size(); i++) {
if(s[i] <= 'Z' && s[i] >= 'A') {
if(!vis[s[i] + 32]) {
flag = 1;
break;
}
}
vis[s[i]] = true;
}
if(flag || vis.size() != 6) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
return 0;
}

B:Anti-Fibonacci Permutation

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
#include <bits/stdc++.h>

using namespace std;

//如果是1在的位置,后面两者需要调换
void print(int x, int n) {
vector<int>vec;
int t = n;
while(t--) {
vec.push_back(x%n);
x++;
}
for(int i = 0; i < vec.size(); i++) {
if(vec[i] == 0 && i < vec.size() - 2) {
swap(vec[i + 1], vec[i + 2]);
}
cout << vec[i] + 1 << " ";
}
cout << endl;
}

int main()
{
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
print(i, n);
}
}
return 0;
}

C:Increase Subarray Sums

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
#include <bits/stdc++.h>

using namespace std;
#define ll long long

const int maxn = 5100;
const int mod = 1000000007;

ll a[maxn];
ll sum[maxn];
int main()
{
int t;
cin >> t;
while(t--) {
int n, x;
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] += a[i-1];
sum[i] = min(sum[i-1], a[i]);
}
long long ans = 0;
for (int i=0; i<=n; i++) {
for (int j=i; j<=n; j++) {
ans = max(ans, a[j] - sum[j-i] + i*x);
}
cout << ans << " ";
}
cout << endl;
}
return 0;
}