QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141306 | #6516. New but Nostalgic Problem | cy1999 | WA | 56ms | 73468kb | C++ | 1.3kb | 2023-08-17 10:35:56 | 2023-08-17 10:35:59 |
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;
}
p = tr[p].son[s[i] - 'a'];
tr[p].siz++;
}
}
void init()
{
scanf("%d %d", &n, &num);
for(int i = 1; i <= n; i++)
{
string s;
cin >> s;
ist(s);
}
}
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 clr()
{
// for(int i = 0; i <= cntn; i++)
// {
// tr[i].siz = 0;
// for(int j = 0; j < E; j++)
// {
// tr[i].son[j] = 0;
// }
// }
flag = 0;
}
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
init();
solve();
clr();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
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: 56ms
memory: 73468kb
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'