QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#703673#6516. New but Nostalgic Problemlllei#WA 17ms5692kbC++201.3kb2024-11-02 18:11:232024-11-02 18:11:25

Judging History

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

  • [2024-11-02 18:11:25]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:5692kb
  • [2024-11-02 18:11:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int son[maxn][26],cnt[maxn];
int idx=0;
void insert(string s)
{
    int len=s.size(),cur=0;
    for(int i=0;i<len;i++)
    {
        int c=s[i]-'a';
        if(!son[cur][c])
        {
            son[cur][c]=++idx;
            memset(son[idx],0,sizeof(son[idx]));
            cnt[idx]=0;
        }
        cur=son[cur][c];
        cnt[cur]++;
    }
}
vector<char>ans;
void dfs(int u,int now)
{
    int sum=0;
    for(int c=0;c<26;c++)if(cnt[son[u][c]])sum++;
    if(sum>=now)return ;
    for(int c=0;c<26;c++)
    if(cnt[son[u][c]])
    {
        if(now-sum+1<=cnt[son[u][c]])
        {
            ans.push_back(c+'a');
            dfs(son[u][c],now-sum+1);
            break;
        }
    }
}
int n,k;
int T;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>T;
    while(T--)
    {
        ans.clear();
        memset(son[0],0,sizeof(son[0]));
        idx=0;
        cin>>n>>k;
        for(int i=1;i<=n;i++)
        {
            string s;
            cin>>s;
            insert(s);
        }
        dfs(0,k);
        if(ans.size()==0)cout<<"EMPTY\n";
        else 
        {
            for(auto c:ans)cout<<c;
            cout<<'\n';
        }
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5628kb

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: 17ms
memory: 5692kb

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
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
o
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
t
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPT...

result:

wrong answer 469th lines differ - expected: 'd', found: 'EMPTY'