QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#702999 | #6516. New but Nostalgic Problem | libantian# | WA | 39ms | 3892kb | C++23 | 1.8kb | 2024-11-02 16:56:31 | 2024-11-02 16:56:32 |
Judging History
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()
const int N=1000010;
int son[N][26],cnt[N],idx;
int n,m;string res;
void init(int p){
for(int i=0;i<26;i++){
if(son[p][i]){
init(son[p][i]);
cnt[son[p][i]]=0;
son[p][i]=0;
}
}
}
void insert(string s){
int p=0;
for(int i=0;i<s.size();i++){
int u=s[i]-'a';
if(!son[p][u])son[p][u]=++idx;
p=son[p][u];
cnt[p]++;
}
}
void query(int p){
if(m<=1)return ;
int sum=0;
int pos=-1;
for(int i=0;i<26;i++){
if(son[p][i]){
//sum+=cnt[son[p][i]];
if(cnt[son[p][i]])sum++;
}
}
if(sum>=m)return;
for(int i=0;i<26;i++){
if(son[p][i]){
//sum+=cnt[son[p][i]];
if(cnt[son[p][i]]>=2)sum+=cnt[son[p][i]]-1,pos=i;
}
if(sum>=m)break;
}
if(pos==-1)return ;
for(int i=pos+1;i<26;i++){
if(son[p][i])m--;
}
for(int i=0;i<pos;i++){
if(cnt[son[p][i]]>=2)m-=cnt[son[p][i]];
}
m=max(m,(int)2);
res+=(char)(pos+'a');
query(son[p][pos]);
}
void solve(){
init(0);
idx=0;
cin>>n>>m;
res.clear();
for(int i=1;i<=n;i++){
string s;
cin>>s;
insert(s);
}
query(0);
if(res.size()==0)cout<<"EMPTY"<<endl;
else cout<<res<<endl;
}
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: 0ms
memory: 3808kb
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: 39ms
memory: 3892kb
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 4030th lines differ - expected: 'n', found: 'nl'