QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189867 | #2871. Clean Up! | MaGnsi0# | WA | 0ms | 3848kb | C++17 | 1.6kb | 2023-09-28 01:07:38 | 2023-09-28 01:07:38 |
Judging History
answer
/**
* author: MaGnsi0
* created: 27.09.2023 19:58:09
**/
#include <bits/stdc++.h>
using namespace std;
const int M = 26;
struct node {
int w;
array<int, M> next;
node() {
w = 0;
for (int i = 0; i < M; ++i) {
next[i] = -1;
}
}
};
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, k;
cin >> n >> k;
vector<node> T(1);
for (int i = 0; i < n; ++i) {
string s; cin >> s;
int j = 0;
for (char c : s) {
T[j].w++;
if (T[j].next[c - 'a'] == -1) {
T[j].next[c - 'a'] = (int)T.size();
T.push_back(node());
}
j = T[j].next[c - 'a'];
}
T[j].w++;
}
int ans = 0;
function<int(int)> dfs = [&](int v) {
if (T[v].w == k) {
ans++;
return 0;
}
if (T[v].w < k) {
return T[v].w;
}
vector<int> have;
for (int u = 0; u < M; ++u) {
if (T[v].next[u] != -1) {
have.push_back(dfs(T[v].next[u]));
}
}
int sum = accumulate(have.begin(), have.end(), 0);
sort(have.rbegin(), have.rend());
for (int x : have) {
if (sum == k) {
ans++;
return 0;
}
if (sum < k) {
return sum;
}
sum -= x;
ans++;
}
return sum;
};
int x = dfs(0);
cout << ans + !!x;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
4 2 a abc abd b
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
4 2 d c ab a
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
5 3 please remove all these files
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
2 3 c acbabaaccb
output:
1
result:
ok single line: '1'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3512kb
input:
4 1 ccbc bbacb cacbbb caabcbbcba
output:
4
result:
ok single line: '4'
Test #6:
score: -100
Wrong Answer
time: 0ms
memory: 3668kb
input:
10 2 c bbabcacb a cbc acccaaca abcaac abbacc ccb cacbb aaacab
output:
5
result:
wrong answer 1st lines differ - expected: '7', found: '5'