QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#703795#6516. New but Nostalgic ProblemlibantianTL 1ms7624kbC++231.7kb2024-11-02 18:31:242024-11-02 18:31:26

Judging History

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

  • [2024-11-02 18:31:26]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:7624kb
  • [2024-11-02 18:31:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define fi first
#define se second
#define all(_a) _a.begin(), _a.end()

#define rep(i,p,q) for (int i=(p);i<=(q);i++)
const int N=1000010;
int son[N][30],cnt[N],idx,a[N];
int n,m,flag,t;string res;

void insert(string s){
    int p=0;
    for(int i=0;i<s.size();i++){
        int u=s[i]-'a'+1;
        if(!son[p][u]) son[p][u]=++idx,cnt[p]++;
        p=son[p][u];
    }
    son[p][0]=1,cnt[p]++;
}
void print(int x) {flag=1; if (!x) puts("EMPTY"); else {rep(i,1,x) putchar(a[i]+96); puts("");}}
void dfs(int p,int x){
    if (flag) return;
    //printf("%d %d\n",p,cnt[p]);
    if (t>=m) return print(x-2),void();
    t+=cnt[p]-1;
    if (t>=m) return print(x-1),void();
    if (flag) return;
    rep(i,1,26) if (son[p][i]) a[x]=i,dfs(son[p][i],x+1);
}
/*
int b[N];
void dfs1(int x,int p) {
    int q=0;
    rep(i,1,26) if (son[x][i]) q++,b[p]=i,dfs1(son[x][i],p+1);
    //if (son[x][0]) {rep(i,1,p-1) putchar(b[i]+96); puts("");}
    //if (q>1) cout<<cnt[x]<<" "<<q<<"\n";
}*/
int last;
void solve(){
    for(int i=0;i<=last+2;i++){
        cnt[i]=0;
        for(int j=0;j<26;j++)son[i][j]=0;
    }
    idx=0;
    cin>>n>>m;
    res.clear();
    int num=0;
    last=0;
    flag=0;
    t=1;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        last+=s.size();
        insert(s);
    }
  //  dfs1(0,1);
    dfs(0,1);
}
signed main(){
   ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << setiosflags(ios::fixed) << setprecision(15);
    int T;
    T=1;
    cin>>T;
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time Limit Exceeded

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
brclvcmzstpidqmkzzoy
EMPTY
EMPTY
plfdlzm
EMPTY
EMPTY
aemmbzvcz
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
czk
EMPTY
EMPTY
jgggzzzzz...

result: