QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153473#6516. New but Nostalgic ProblemqzezWA 18ms7740kbC++141.7kb2023-08-30 07:21:492023-08-30 07:21:50

Judging History

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

  • [2023-08-30 07:21:50]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:7740kb
  • [2023-08-30 07:21:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
	if(x.empty())return out<<"[]";
	out<<'['<<x[0];
	for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
	return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
	cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
	cerr<<x<<' ',debug(y...);
}
const int N=1e6+10,M=26;
int T,n,m,k,ch[N][26],cnt[N],ed[N],ans[N];
char a[N];
void insert(){
	int n=strlen(a+1),u=0;
	for(int i=1;i<=n;i++){
		cnt[u]++;
		int &v=ch[u][a[i]-'a'];
		if(!v)v=++k;
		u=v;
	}
	cnt[u]++,ed[u]++;
}
int pre[M],suf[M];
string res;
bool flag;
void dfs(int u){
	if(flag)return;
	pre[0]=suf[M-1]=0;
	for(int i=0;i+1<M;i++){
		int v=ch[u][i];
		if(!v)continue;
		pre[i+1]=pre[i]+cnt[v];
	}
	for(int i=M-1;i>0;i--){
		int v=ch[u][i];
		if(!v)continue;
		suf[i-1]=suf[i]+!!cnt[v];
	}
	int tot=0;
	for(int i=0;i<M;i++){
		int v=ch[u][i];
		if(!v)continue;
		tot+=!!cnt[v];
	}
	// debug(u,ans[u],tot);
	if(ans[u]+tot>=m){
		flag=1;
		if(!u){
			puts("EMPTY");
		}else{
			cout<<res<<'\n';
		}
		return;
	}
	for(int i=0;i<M;i++){
		int v=ch[u][i];
		if(!v)continue;
		ans[v]=ans[u]+pre[i]+suf[i]+ed[v];
		res+='a'+i,dfs(v),res.pop_back();
	}
}
void get(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%s",a+1),insert();
	}
	flag=0;
	dfs(0);
	for(;~k;k--){
		memset(ch[k],0,sizeof ch[k]);
		cnt[k]=ed[k]=ans[k]=0;
	}
	k=0;
}
int main(){
	for(scanf("%d",&T);T--;)get();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 7740kb

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: 18ms
memory: 7680kb

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
ks
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
b
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
a
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
c
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMP...

result:

wrong answer 3rd lines differ - expected: 'w', found: 'ks'