QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189590 | #2871. Clean Up! | triplem5ds# | WA | 1ms | 3516kb | C++23 | 1.7kb | 2023-09-27 17:49:37 | 2023-09-27 17:49:38 |
Judging History
answer
/// Msaa el 5ra
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
#define f(i, a, b) for(int i = a; i < b; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair(x,y)
#define popCnt(x) (__builtin_popcountll(x))
#define int ll
using ll = long long;
using ii = pair<int, int>;
using ull = unsigned long long;
const int N = 5e5 + 5, LG = 18, MOD = 1e9 + 7;
const long double PI = acos(-1);
const long double EPS = 1e-7;
int tr[N][26];
int sz[N], ptr;
void add(string s) {
sz[0] += 1;
int cur = 0;
for (char c: s) {
if (!tr[cur][c - 'a']) {
tr[cur][c - 'a'] = ++ptr;
}
cur = tr[cur][c - 'a'];
sz[cur] += 1;
}
}
int dfs(int node, int limit) {
if (sz[node] <= limit) {
return 1;
}
vector<int> vec;
f(i, 0, 26)if (tr[node][i])vec.push_back(tr[node][i]);
sort(all(vec), [&](int x, int y) {
return sz[x] > sz[y];
});
int ans = 0, cur = sz[node];
for (auto x: vec) {
if (cur <= limit) {
return ans + 1;
}
ans += dfs(x, limit);
cur -= sz[x];
}
return ans + (!!cur);
}
void doWork() {
int n, k;
cin >> n >> k;
f(i, 0, n) {
string s;
cin >> s;
add(s);
}
cout << dfs(0, k) << '\n';
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(0);
cin.tie(0);
#endif // ONLINE_JUDGE
int t = 1;
// cin >> t;
while (t--) {
doWork();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3516kb
input:
4 2 a abc abd b
output:
3
result:
wrong answer 1st lines differ - expected: '2', found: '3'