QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#141314#6516. New but Nostalgic Problemcy1999WA 58ms35352kbC++1.5kb2023-08-17 10:42:472023-08-17 10:42:47

Judging History

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

  • [2023-08-17 10:42:47]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:35352kb
  • [2023-08-17 10:42:47]
  • 提交

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'