QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#234230#6516. New but Nostalgic Problemucup-team1198#WA 67ms7752kbC++201.8kb2023-11-01 15:01:092023-11-01 15:01:10

Judging History

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

  • [2023-11-01 15:01:10]
  • 评测
  • 测评结果:WA
  • 用时:67ms
  • 内存:7752kb
  • [2023-11-01 15:01:09]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define pii pair<int, int>
#define ld long double
#define all(a) (a).begin(), (a).end()

const int MAXN = 1'100'100;
int go[MAXN][26];
int cnt[MAXN];
int sum[MAXN];

int nodes_cnt = 0;

int node() {
    fill(go[nodes_cnt], go[nodes_cnt] + 26, -1);
    cnt[nodes_cnt] = 0;
    ++nodes_cnt;
    return nodes_cnt - 1;
}

void dfs_sum(int v) {
    sum[v] = cnt[v];
    for (int i = 0; i < 26; ++i) {
        if (go[v][i] != -1) {
            dfs_sum(go[v][i]);
            sum[v] += sum[go[v][i]];
        }
    }
}

void dfs_ans(int v, int k, string& ans) {
    k -= cnt[v];
    int have_edges = 0;
    for (int i = 0; i < 26; ++i) {
        if (go[v][i] != -1) {
            ++have_edges;
        }
    }
    if (have_edges >= k) {
        return;
    }
    int rest_sum = sum[v] - cnt[v];
    for (int i = 25; i >= 0; --i) {
        if (go[v][i] != -1) {
            if (rest_sum - sum[go[v][i]] + 1 < k) {
                ans += char('a' + i);
                dfs_ans(go[v][i], k - (rest_sum - sum[go[v][i]]), ans);
            } else {
                --k;
                rest_sum -= sum[go[v][i]];
            }
        }
    }
}

void solve() {
    nodes_cnt = 0;
    node();
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        int cur = 0;
        for (char c : s) {
            if (go[cur][c - 'a'] == -1) {
                go[cur][c - 'a'] = node();
            }
            cur = go[cur][c - 'a'];
        }
        ++cnt[cur];
    }
    dfs_sum(0);
    string ans;
    dfs_ans(0, k, ans);
    if (ans.empty())
        cout << "EMPTY\n";
    else
        cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 7688kb

input:

2
5 3
gdcpc
gdcpcpcp
suasua
suas
sususua
3 3
a
b
c

output:

gdcpc
EMPTY

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 67ms
memory: 7752kb

input:

20000
5 3
apveofpr
irdbqk
rnionnjjrk
wrpihlsw
ofylfsriof
5 4
iiltghqg
kybhogptqf
jfnmqxzrdq
rpztcluq
tzmnrcjae
5 5
ysp
vujmkkcutl
ksawqeiiaf
waukilaq
wmlsutlued
5 3
pikybt
yiqmqvtjeq
tyrsoihf
vnvjrxpus
cuubpacubb
5 2
rihuvikhg
twrsuoervz
ukiekoohw
eysqgndpf
sxswpeqtaf
5 5
vxzhicbp
nvtdbgqal
jilppvpt...

output:

EMPTY
EMPTY
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
o
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
t
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPT...

result:

wrong answer 469th lines differ - expected: 'd', found: 'dc'