QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#228153 | #6516. New but Nostalgic Problem | sjk1686959421 | WA | 19ms | 38592kb | C++20 | 1.6kb | 2023-10-28 12:53:01 | 2023-10-28 12:53:01 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
int p[1000010][26],cnt=0,res[1000010],ma=-1;
void add(string s){
int e=0;
for(int i=0;i<s.size();i++){
int x=s[i]-'a';
if(!p[e][x]){
p[e][x]=++cnt;
}
e=p[e][x];
res[e]++;
}
}
void f(string s){
int e=0,len=0;
for(int i=0;i<s.size();i++){
int x=s[i]-'a';
e=p[e][x];
len++;
if(res[e]>1){
ma=max(ma,len);
}
}
}
vector<string>ans;
void ff(string s){
int e=0,len=0;
for(int i=0;i<s.size();i++){
int x=s[i]-'a';
e=p[e][x];
len++;
if(len==ma&&res[e]>1){
ans.push_back(s.substr(0,len));
}
}
}
string a[1000010];
void slove(){
ma=-1;
ans.clear();
cnt=0;
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
res[i]=0;
}
for(int i=1;i<=n;i++){
cin>>a[i];
add(a[i]);
}
for(int i=1;i<=n;i++){
f(a[i]);
}
for(int i=1;i<=n;i++){
ff(a[i]);
}
/*sort(ans.begin(),ans.end());
for(int i=0;i<ans.size();i++){
cout<<ans[i]<<endl;
}*/
if(ans.size()){
cout<<ans[0]<<endl;
}else{
cout<<"EMPTY"<<endl;
}
for(int i=0;i<cnt;i++){
for(int j=0;j<26;j++){
p[i][j]=0;
}
}
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int _=1;
cin>>_;
while(_--){
slove();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 37864kb
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: 19ms
memory: 38592kb
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 kybhogptqf vujmkkcutl yiqmqvtjeq twrsuoervz jilppvptxq onsslljhqc nbmmwhrzu xncianfdkv oohjlhgpzn ephnxqsczy bfxgtgqvxk vkahoqapmk jnfgujqkp dpsvxbvdkm dgllkckolp xajnljlwg aetishqhvr attwvoajhu wjfpdzmxj dmjisbxwad uffzsgollp zzrmtdnexv ewlsqzrigm rrfytrzvoa zbmmwkruqf owihjjilxr nslmjhwgor v...
result:
wrong answer 2nd lines differ - expected: 'EMPTY', found: 'kybhogptqf'