QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748815#6516. New but Nostalgic ProblemharlemTL 0ms0kbC++141.1kb2024-11-14 21:32:342024-11-14 21:32:36

Judging History

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

  • [2024-11-14 21:32:36]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-14 21:32:34]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

const int N=1e6+5;

int n,k;

int cnt=1;
int num[N],und[N];
int nxt[N][26];

void insert(string s){
    int now=1;
    und[1]++;
    for(int i=0;i<s.size();i++){
        int &ne=nxt[now][s[i]-'a'];
        if(!ne)ne=++cnt;
        und[ne]++;
        now=ne;
    }
    num[now]++;
}

void solve(){
    int now=1;
    while(1){
        int chs=num[now];
        for(int i=0;i<26;i++){
            if(und[nxt[now][i]])chs++;
        }
        if(chs>=k){
            if(now==1)cout<<"EMPTY";
            break;
        }
        for(int i=0;i<26;i++){
            if(und[nxt[now][i]]){
                chs+=und[nxt[now][i]]-1;
                if(chs>=k){
                    k-=chs-und[nxt[now][i]];
                    now=nxt[now][i];
                    cout<<char(i+'a');
                    break;
                }
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>k;
    string s;
    for(int i=1;i<=n;i++){
        cin>>s;
        insert(s);
    }
    solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

2
5 3
gdcpc
gdcpcpcp
suasua
suas
sususua
3 3
a
b
c

output:


result: