QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#420407 | #6516. New but Nostalgic Problem | whizhou | WA | 44ms | 222464kb | C++14 | 1.6kb | 2024-05-24 17:33:54 | 2024-05-24 17:33:54 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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'