Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
for _ in range(int(input())):
n = int(input())
s = input()
print(sum([s.count(chr(ord('A') + i)) >= i + 1 for i in range(26)]))
1914B - Preparing for the Contest
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = list(range(1, k + 1)) + list(range(n, k, -1))
print(*a)
Idea: Roms
Tutorial
Tutorial is loading...
Solution (Neon)
fun main() = repeat(readLine()!!.toInt()) {
val (n, k) = readLine()!!.split(" ").map { it.toInt() }
val a = readLine()!!.split(" ").map { it.toInt() }
val b = readLine()!!.split(" ").map { it.toInt() }
var (res, sum, mx) = intArrayOf(0, 0, 0)
for (i in 0 until minOf(n, k)) {
sum += a[i]
mx = maxOf(mx, b[i])
res = maxOf(res, sum + mx * (k - i - 1))
}
println(res)
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (awoo)
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
def get_best3(a):
mx1, mx2, mx3 = -1, -1, -1
for i in range(len(a)):
if mx1 == -1 or a[i] > a[mx1]:
mx3 = mx2
mx2 = mx1
mx1 = i
elif mx2 == -1 or a[i] > a[mx2]:
mx3 = mx2
mx2 = i
elif mx3 == -1 or a[i] > a[mx3]:
mx3 = i
return (mx1, mx2, mx3)
ans = 0
for x in get_best3(a):
for y in get_best3(b):
for z in get_best3(c):
if x != y and x != z and y != z:
ans = max(ans, a[x] + b[y] + c[z])
print(ans)
1914E1 - Game with Marbles (Easy Version)
1914E2 - Game with Marbles (Hard Version)
Idea: adedalic
Tutorial
Tutorial is loading...
Solution (adedalic)
#include<bits/stdc++.h>
using namespace std;
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define sz(a) int((a).size())
typedef long long li;
// S = sum a_i - sum b_i
// if Bob made all steps: then S = 0 - sum (b_i - 1)
// each Alice step: S += (a_i - 1) + (b_i - 1) i. e. the bigger (a_i + b_i) the better
int n;
vector<int> a, b;
inline bool read() {
if(!(cin >> n))
return false;
a.resize(n);
b.resize(n);
fore (i, 0, n)
cin >> a[i];
fore (i, 0, n)
cin >> b[i];
return true;
}
inline void solve() {
vector<int> ids(n);
iota(ids.begin(), ids.end(), 0);
sort(ids.begin(), ids.end(), [&](int i, int j) {
return a[i] + b[i] > a[j] + b[j];
});
li S = 0;
fore (i, 0, n) {
if (i & 1)
S -= b[ids[i]] - 1;
else
S += a[ids[i]] - 1;
}
cout << S << endl;
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
int tt = clock();
#endif
// ios_base::sync_with_stdio(false);
// cin.tie(0), cout.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
for(int i = 0; i < t; i++)
{
if(read()) {
solve();
#ifdef _DEBUG
cerr << "TIME = " << clock() - tt << endl;
tt = clock();
#endif
}
}
return 0;
}
1914F - Programming Competition
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
const int N = 222222;
int n;
int sz[N];
vector<int> g[N];
void init(int v) {
sz[v] = 1;
for (int u : g[v]) {
init(u);
sz[v] += sz[u];
}
}
int calc(int v, int k) {
int tot = 0, mx = -1;
for (int u : g[v]) {
tot += sz[u];
if (mx == -1 || sz[mx] < sz[u]) mx = u;
}
if (tot == 0) return 0;
if (sz[mx] - k <= tot - sz[mx])
return (tot - k) / 2;
int add = tot - sz[mx];
return add + calc(mx, max(0, k + add - 1));
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; ++i) g[i].clear();
for (int i = 1; i < n; ++i) {
int p; cin >> p;
g[p - 1].push_back(i);
}
init(0);
cout << calc(0, 0) << '\n';
}
}
1914G1 - Light Bulbs (Easy Version)
1914G2 - Light Bulbs (Hard Version)
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (BledDest)
#include<bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
int add(int x, int y)
{
return (((x + y) % MOD) + MOD) % MOD;
}
int mul(int x, int y)
{
return (x * 1ll * y) % MOD;
}
mt19937_64 rnd(98275314);
long long gen()
{
long long x = 0;
while(x == 0)
x = rnd();
return x;
}
vector<int> c;
vector<int> g;
int process_block(int l, int r)
{
int ans = 0;
while(l < r)
{
if(g[l] != -1 && g[l] < r)
l = g[l];
else
{
ans++;
l++;
}
}
return ans;
}
void solve()
{
int n;
scanf("%d", &n);
int size = 0, cnt = 1;
c.resize(n * 2);
g.resize(n * 2, -1);
for(int i = 0; i < 2 * n; i++)
{
scanf("%d", &c[i]);
--c[i];
}
vector<long long> val(n);
for(int i = 0; i < n; i++) val[i] = gen();
map<long long, int> last;
long long cur = 0;
last[0] = 0;
for(int i = 0; i < n * 2; i++)
{
cur ^= val[c[i]];
if(cur == 0)
{
size++;
cnt = mul(cnt, process_block(last[0], i + 1));
last.clear();
}
else if(last.count(cur))
{
g[last[cur]] = i + 1;
}
last[cur] = i + 1;
}
printf("%d %d\n", size, cnt);
c.clear();
g.clear();
}
int main()
{
int t;
scanf("%d", &t);
for(int i = 0; i < t; i++) solve();
}