QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#189602#2871. Clean Up!triplem5ds#WA 1ms5568kbC++231.9kb2023-09-27 18:01:422023-09-27 18:01:43

Judging History

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

  • [2023-09-27 18:01:43]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5568kb
  • [2023-09-27 18:01:42]
  • 提交

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;
int par[N];

void add(string s) {
    sz[0] += 1;
    int cur = 0;
    for (char c: s) {
        if (!tr[cur][c - 'a']) {
            tr[cur][c - 'a'] = ++ptr;
            par[ptr] = cur;
        }
        cur = tr[cur][c - 'a'];
        sz[cur] += 1;
    }
}

set<ii> st;

void killNode(int node) {
    st.erase({sz[node], node});
    f(k, 0, 26)
        if (tr[node][k])
            killNode(tr[node][k]);
}

void doWork() {
    int n, k;
    cin >> n >> k;
    f(i, 0, n) {
        string s;
        cin >> s;
        add(s);
    }
    for (int i = 0; i <= ptr; i++) {
        st.insert({sz[i], i});
    }
    int ans = 0;
    while (st.size() && st.rbegin()->F) {
        auto it = st.upper_bound({k + 1, -1});
        --it;
        int node = it->S;
        ans += 1;
        killNode(node);
        int cur = node;
        do {
            cur = par[cur];
            st.erase({sz[cur], cur});
            sz[cur] -= sz[node];
            st.insert({sz[cur], cur});
        } while (cur);
    }
    cout << ans << '\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: 5488kb

input:

4 2
a
abc
abd
b

output:

2

result:

ok single line: '2'

Test #2:

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

input:

4 2
d
c
ab
a

output:

2

result:

ok single line: '2'

Test #3:

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

input:

5 3
please
remove
all
these
files

output:

3

result:

ok single line: '3'

Test #4:

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

input:

2 3
c
acbabaaccb

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4 1
ccbc
bbacb
cacbbb
caabcbbcba

output:

4

result:

ok single line: '4'

Test #6:

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

input:

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

output:

7

result:

ok single line: '7'

Test #7:

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

input:

9 1
aababaaab
bc
baabbaaacc
bcbccbaaaa
ac
accaab
bbbbc
aacbaa
ab

output:

9

result:

ok single line: '9'

Test #8:

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

input:

5 2
bbaac
baac
abbbcacab
bca
ccbbbbccc

output:

4

result:

wrong answer 1st lines differ - expected: '3', found: '4'