6923 | 2023-12-19 22:04:00 | TuruTamas | Szöveg egyenetlenség | cpp17 | Elfogadva 100/100 | 232ms | 3244 KiB |
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
ifstream in_file("minta/be1.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
const int abc_num = ('z'-'a'+1)*2;
ll F, T, Q, len, K, num0, r, rollsum;
vector<ll> nums(abc_num, 0), nums_adj(abc_num, 0);
char C;
int ctoi(char c) {
return (c >= 'a') ? ('Z'-'A'+1 + c-'a') : (c-'A');
}
int main() {
INTHENAMEOFGOD
input >> T;
for (ll t = 0; t < T; t++) {
input >> Q;
len = 0;
nums.assign(abc_num, 0);
num0 = abc_num;
for (ll q = 0; q < Q; q++) {
input >> F >> C >> K;
len += F;
num0 -= nums[ctoi(C)] == 0;
nums[ctoi(C)] += F;
copy_n(nums.begin(), abc_num, nums_adj.begin());
sort(nums_adj.begin(), nums_adj.end());
ll &maxval = nums_adj.back();
maxval += min(len-maxval, K);
rollsum = r = 0;
ll *i = &nums_adj[0]+num0;
for (; i < &maxval; i++) {
ll le = min(*i, K);
K -= le;
*i -= le;
r += *i*(len-*i-rollsum);
rollsum += *i;
}
r += maxval*(len-maxval-rollsum);
cout << r << "\n";
}
}
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 3ms | 1884 KiB | ||||
subtask2 | 20/20 | ||||||
2 | Elfogadva | 3ms | 2116 KiB | ||||
3 | Elfogadva | 3ms | 2316 KiB | ||||
4 | Elfogadva | 3ms | 2408 KiB | ||||
5 | Elfogadva | 3ms | 2628 KiB | ||||
6 | Elfogadva | 3ms | 2548 KiB | ||||
subtask3 | 20/20 | ||||||
7 | Elfogadva | 119ms | 2600 KiB | ||||
8 | Elfogadva | 119ms | 2656 KiB | ||||
9 | Elfogadva | 119ms | 2600 KiB | ||||
10 | Elfogadva | 119ms | 2616 KiB | ||||
11 | Elfogadva | 120ms | 2820 KiB | ||||
subtask4 | 30/30 | ||||||
12 | Elfogadva | 165ms | 2852 KiB | ||||
13 | Elfogadva | 119ms | 2844 KiB | ||||
14 | Elfogadva | 162ms | 2868 KiB | ||||
15 | Elfogadva | 163ms | 3124 KiB | ||||
16 | Elfogadva | 158ms | 3152 KiB | ||||
subtask5 | 30/30 | ||||||
17 | Elfogadva | 232ms | 3148 KiB | ||||
18 | Elfogadva | 119ms | 3096 KiB | ||||
19 | Elfogadva | 216ms | 3044 KiB | ||||
20 | Elfogadva | 212ms | 3028 KiB | ||||
21 | Elfogadva | 206ms | 3244 KiB |