QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#228153#6516. New but Nostalgic Problemsjk1686959421WA 19ms38592kbC++201.6kb2023-10-28 12:53:012023-10-28 12:53:01

Judging History

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

  • [2023-10-28 12:53:01]
  • 评测
  • 测评结果:WA
  • 用时:19ms
  • 内存:38592kb
  • [2023-10-28 12:53:01]
  • 提交

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'