Educational Codeforces Round 93 (Rated for Div. 2)
A
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
ll a[N];
int main() {
IO;
for (cin >> _; _; --_) {
cin >> n;
rep (i, 1, n) cin >> a[i];
if ((ll)a[1] + a[2] <= a[n]) cout << "1 2 " << n << '\n';
else cout << "-1\n";
}
return 0;
}
B
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
int main() {
IO;
for (cin >> _; _; --_) {
string s; cin >> s;
VI a;
int cnt = 0;
for (char i : s) {
if (i == '1') ++cnt;
else if (cnt) a.pb(cnt), cnt = 0;
}
if (cnt) a.pb(cnt);
sort(all(a));
ll ans = 0;
for (int i = 1; ; ++i) {
if (a.empty()) break;
if (i & 1) ans += a.back();
a.pop_back();
}
cout << ans << '\n';
}
return 0;
}
C
统计前缀和出现次数, 对应区间就是 0
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 1e5 + 5;
int n, m, _, k;
ll ans;
string s;
int main() {
IO;
for (cin >> _; _; --_) {
cin >> n >> s;
map<int, int> st; st[0] = 1;
ll res = 0, ans = 0;
rep(i, 0, n - 1) {
res += s[i] - '0' - 1;
ans += st[res]++;
}
cout << ans << '\n';
}
return 0;
}
D
dp
#include <bits/stdc++.h>
#define all(n) (n).begin(), (n).end()
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define sqr(n) (n)*(n)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define IO ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef double db;
const int N = 200 + 5;
int n, m, _, k;
int a[N], b[N], c[N];
ll f[N][N][N];
int main() {
IO; cin >> n >> m >> k;
rep (i, 1, n) cin >> a[i];
sort(a + 1, a + n + 1);
rep (i, 1, m) cin >> b[i];
sort(b + 1, b + 1 + m);
rep (i, 1, k) cin >> c[i];
sort(c + 1, c + 1 + k);
per (i, n, 0)
per (j, m, 0)
per (h, k, 0) {
if (i && j)
f[i - 1][j - 1][h] = max(f[i - 1][j - 1][h], f[i][j][h] + a[i] * b[j]);
if (i && h)
f[i - 1][j][h - 1] = max(f[i - 1][j][h - 1], f[i][j][h] + a[i] * c[h]);
if (j && h)
f[i][j - 1][h - 1] = max(f[i][j - 1][h - 1], f[i][j][h] + b[j] * c[h]);
}
ll ans = 0;
rep (i, 0, n)
rep (j, 0, m)
rep (h, 0, k)
ans = max(ans, f[i][j][h]);
cout << ans;
return 0;
}