QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153473 | #6516. New but Nostalgic Problem | qzez | WA | 18ms | 7740kb | C++14 | 1.7kb | 2023-08-30 07:21:49 | 2023-08-30 07:21:50 |
Judging History
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'