QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#189590#2871. Clean Up!triplem5ds#WA 1ms3516kbC++231.7kb2023-09-27 17:49:372023-09-27 17:49:38

Judging History

你现在查看的是最新测评结果

  • [2023-09-27 17:49:38]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3516kb
  • [2023-09-27 17:49:37]
  • 提交

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();
    }
}

详细

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'