QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#420407#6516. New but Nostalgic ProblemwhizhouWA 44ms222464kbC++141.6kb2024-05-24 17:33:542024-05-24 17:33:54

Judging History

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

  • [2024-05-24 17:33:54]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:222464kb
  • [2024-05-24 17:33:54]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define N 1000000

#define fo(i, x, y) for(int i = x, endI = y; i <= endI; ++ i)

struct Trie {
    int son[26], sz, diffSz = 0;
} st[N << 1];

int tot, rt;

char ch[N + 1];

int n, m;

void insert(int &t, int k, int len) {
    if (! t)
        t = ++tot;
    ++st[t].sz;
    if (k <= len)
        insert(st[t].son[ch[k] - 'a'], k + 1, len);
    else
        st[t].diffSz = 1;
}

void putMax(int t) {
    for (int i = 25; i >= 0; -- i)
        if (st[st[t].son[i]].sz > 1) {
            putchar(i + 'a');
            putMax(st[t].son[i]);
            return;
        }
}

bool query(int t, int k) {
    if (st[t].diffSz >= k)
        return 0;
    fo(i, 0, 25) if (st[t].son[i]) {
        int ls = st[t].son[i];
        if (st[ls].sz >= k) {
            // if (st[ls].sz > 1) {
            putchar(i + 'a');
            query(ls, k);
            // }
            return 1;
        } else
            if ((k -= st[ls].sz) == 1) {
                if (st[ls].sz > 1) {
                    putchar(i + 'a');
                    putMax(ls);
                    return 1;
                }
                return 0;
            }
    }
    return 0;
}

int main() {
    int T; scanf("%d", &T);
    while (T--) {
        int new_rt = rt = ++tot;
        scanf("%d %d\n", &n, &m);
        fo(i, 1, n) {
            scanf("%s", ch + 1);
            insert(rt, 1, strlen(ch + 1));
        }

        fo(i, new_rt, tot) fo(j, 0, 25)
            if (st[i].son[j])
                ++st[i].diffSz;

        puts(query(rt, m) ? "" : "EMPTY");
    }

    return 0;
}

详细

Test #1:

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

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: 44ms
memory: 222464kb

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 77th lines differ - expected: 'd', found: 'EMPTY'