QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#189586#2871. Clean Up!triplem5ds#WA 1ms3516kbC++231.7kb2023-09-27 17:41:592023-09-27 17:42:01

Judging History

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

  • [2023-09-27 17:42:01]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3516kb
  • [2023-09-27 17:41:59]
  • 提交

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

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: 100
Accepted
time: 1ms
memory: 3516kb

input:

4 2
a
abc
abd
b

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3440kb

input:

4 2
d
c
ab
a

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3436kb

input:

5 3
please
remove
all
these
files

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 1ms
memory: 3448kb

input:

2 3
c
acbabaaccb

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3440kb

input:

4 1
ccbc
bbacb
cacbbb
caabcbbcba

output:

4

result:

ok single line: '4'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3440kb

input:

10 2
c
bbabcacb
a
cbc
acccaaca
abcaac
abbacc
ccb
cacbb
aaacab

output:

7

result:

ok single line: '7'

Test #7:

score: -100
Wrong Answer
time: 1ms
memory: 3448kb

input:

9 1
aababaaab
bc
baabbaaacc
bcbccbaaaa
ac
accaab
bbbbc
aacbaa
ab

output:

7

result:

wrong answer 1st lines differ - expected: '9', found: '7'