QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#141186 | #6516. New but Nostalgic Problem | cy1999 | TL | 0ms | 3560kb | C++ | 1.6kb | 2023-08-17 09:18:38 | 2023-08-17 09:18:40 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
const int E = 26, S = 1000000;
int n, num;
struct Tr
{
int son[E + 5];
int siz;
}tr[S + 5];
int cntn = 0;
void ist(string s)
{
int len = s.size();
int p = 0;
for(int i = 0; i < len; i++)
{
if(!tr[p].son[s[i] - 'a'])
{
tr[p].son[s[i] - 'a'] = ++cntn;
}
// printf("%d %d\n", p, tr[p].son[s[i] - 'a']);
p = tr[p].son[s[i] - 'a'];
tr[p].siz++;
// printf("%d %d\n", p, tr[p].siz);
}
}
void init()
{
scanf("%d %d", &n, &num);
for(int i = 1; i <= n; i++)
{
string s;
cin >> s;
ist(s);
}
}
string ans;
void dfs(int u, int x)
{
// printf("%d %d\n", u, x);
for(int i = 0; i < E; i++)
{
if(tr[u].son[i] && x)
{
// printf("%d %d\n", i, tr[u].son[i]);
x--;
}
}
// printf("%d\n", x);
if(x == 0)
{
return;
}
for(int i = 0; i < E; i++)
{
if(!tr[u].son[i])
{
continue;
}
if(x <= tr[tr[u].son[i]].siz - 1)
{
dfs(tr[u].son[i], x + 1);
ans += (i + 'a');
return;
}
else
{
x -= tr[tr[u].son[i]].siz - 1;
}
}
}
void solve()
{
dfs(0, num);
int la = ans.size();
if(la == 0)
{
printf("EMPTY\n");
}
else
{
for(int i = la - 1; i >= 0; i--)
{
cout << ans[i];
}
printf("\n");
}
}
void clr()
{
for(int i = 0; i <= cntn; i++)
{
tr[i].siz = 0;
for(int j = 0; j < E; j++)
{
tr[i].son[j] = 0;
}
}
ans.clear();
}
int main()
{
// freopen("a.out", "w", stdout);
int T;
scanf("%d", &T);
while(T--)
{
init();
solve();
clr();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3560kb
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
Time Limit Exceeded
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...