QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#141314 | #6516. New but Nostalgic Problem | cy1999 | WA | 58ms | 35352kb | C++ | 1.5kb | 2023-08-17 10:42:47 | 2023-08-17 10:42:47 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
const int E = 26, S = 1000000, N = 1000000;
int n, num;
string st[N + 5];
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[tr[p].son[s[i] - 'a']].siz == 0)
{
tr[p].son[s[i] - 'a'] = ++cntn;
}
p = tr[p].son[s[i] - 'a'];
tr[p].siz++;
}
}
void init()
{
scanf("%d %d", &n, &num);
for(int i = 1; i <= n; i++)
{
cin >> st[i];
ist(st[i]);
}
}
bool flag = 0;
void dfs(int u, int x)
{
for(int i = 0; i < E; i++)
{
if(tr[u].son[i] && x)
{
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)
{
printf("%c", i + 'a');
flag = 1;
dfs(tr[u].son[i], x + 1);
return;
}
else
{
x -= tr[tr[u].son[i]].siz - 1;
}
}
}
void solve()
{
dfs(0, num);
if(!flag)
{
printf("EMPTY");
}
printf("\n");
}
void del(string s)
{
int len = s.size();
int p = 0;
for(int i = 0; i < len; i++)
{
p = tr[p].son[s[i] - 'a'];
tr[p].siz = 0;
}
}
void clr()
{
for(int i = 1; i <= n; i++)
{
del(st[i]);
}
cntn = 0;
flag = 0;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
init();
solve();
clr();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 5ms
memory: 35052kb
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: 58ms
memory: 35352kb
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 EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY ...
result:
wrong answer 3rd lines differ - expected: 'w', found: 'EMPTY'