QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#222537#6516. New but Nostalgic ProblemzhxbWA 10ms5716kbC++201.7kb2023-10-21 17:33:162023-10-21 17:33:16

Judging History

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

  • [2023-10-21 17:33:16]
  • 评测
  • 测评结果:WA
  • 用时:10ms
  • 内存:5716kb
  • [2023-10-21 17:33:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int N=1e6+5;
int cnt[N],ch[N][26];
struct Trie
{
    int idx=0;
    void clear(int p)
    {
        for(int i=0;i<26;i++)
        {
            if(ch[p][i])
            {
                clear(ch[p][i]);
                ch[p][i]=0;
            }
        }
        idx=0;
    }
    void insert(string s)
    {
        int p=0;
        for(int i=0;i<s.length();i++)
        {
            int j=s[i]-'a';
            if(!ch[p][j]) ch[p][j]=++idx;
            p=ch[p][j];
            cnt[p]++;
        }
    }
    string query(string s)
    {
        int p=0;
        string str;
        for(int i=0;i<s.length();i++)
        {
            int j=s[i]-'a';
            if(!ch[p][j]) return str;
            p=ch[p][j];
            str+=s[i];
        }
        return s;
    }

};
void solve()
{
    struct Trie g;
    g.clear(0);
    int n,m;
    cin>>n>>m;
    vector <string> s(n+1);
    for(int i=1;i<=n;i++) cin>>s[i];
    vector <int> cnt(26);
    for(int i=1;i<=n;i++) cnt[s[i][0]-'a']=1;
    int sum=count(cnt.begin(),cnt.end(),1);
    if(sum>=m) {cout<<"EMPTY\n";return;}
    string ans="";
    for(int i=1;i<=n;i++)
    {
        auto str=g.query(s[i]);
        if(str.length())
        {
            if(ans.length()==0) ans=str;
            else ans=min(ans,str);
        }
        g.insert(s[i]);
    }
    cout<<ans<<'\n';
}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int T;
    cin>>T;
    while(T--) 
        solve();
    return 0;
}

详细

Test #1:

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

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: 10ms
memory: 5716kb

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 469th lines differ - expected: 'd', found: 'c'