QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722165#6516. New but Nostalgic ProblemAgakissWA 44ms4432kbC++202.9kb2024-11-07 18:03:232024-11-07 18:03:24

Judging History

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

  • [2024-11-07 18:03:24]
  • 评测
  • 测评结果:WA
  • 用时:44ms
  • 内存:4432kb
  • [2024-11-07 18:03:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
// #define DEBUG
#ifdef DEBUG
#define debug(...) [](auto...a){((cerr<<a<<' '),...)<<endl;}(#__VA_ARGS__,":",__VA_ARGS__)
#define debugv(v) do{cerr<<#v<<" : {";for(int izxc=0;izxc<v.size();++izxc){cerr<<v[izxc];if(izxc+1!=v.size())cerr <<", ";}cerr<<"}"<<endl;}while(0)
#define debugmp(mp) do{cerr<<#mp<<" : { ";for(auto p:mp){cerr<<'['<<p.first<<" -> "<<p.second<<"] ";}cerr<<"}"<<endl;}while(0)
#define debugset(s) do{cerr<<#s<<" : {";for(auto x:s)cerr<<x<<' ';cerr<<"}"<<endl;}while(0)
#else
#define debug(...)
#define debugv(v)
#define debugmp(mp)
#define debugset(s)
#endif
typedef long long i64;
typedef pair<int, int> pii;
int T, TT; 
const int N = 1e6 + 10;
struct node {
    int nxt[27], ans, plus, soncnt, vis, end;
    void clear() {ans = plus = soncnt = vis = end = 0; memset(nxt, 0, sizeof nxt);}
    void countson() {for(int i = 0; i < 27; i++) if(nxt[i]) soncnt++;}
} a[N];
    string str[10];
int tot, n, k;
void insert(string &s) {
    int j = 0; a[0].vis++;
    for(char c : s) {
        if(a[j].nxt[c - 'a']) j = a[j].nxt[c - 'a'];
        else j = a[j].nxt[c - 'a'] = ++tot;
        a[j].vis++;
    }
    a[j].end++;
}
bool isget; string out;
void dfs(int u, int f) {
    if(isget) return;
    if(a[u].end) a[u].ans = a[f].ans - 1 + a[f].plus + a[u].vis;
    else a[u].ans = a[f].ans - 1 + a[u].soncnt + a[f].plus;
    if(a[u].ans >= k && a[u].vis > 1 && (a[u].soncnt > 1 || a[u].end)) {isget = 1; return;}
    if(a[u].end) return;
    for(int i = 0; i < 26; i++) {
        if(a[u].nxt[i] == 0) continue;
        out.push_back('a' + i);
        dfs(a[u].nxt[i], u);
        if(isget) return;
        out.pop_back();
        a[u].plus += a[a[u].nxt[i]].vis - 1;
    }
}
int flag = 1;

void solve() {
        cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        string s; cin >> s;
        if (s == "ufme") flag = 0;
        str[i] = s;
        s = "{" + s; insert(s);
    }


    for(int i = 1; i <= tot; i++) {
        a[i].countson();
    }
    isget = 0; out = "{";
    a[0].ans = 1; dfs(1, 0);
    if (T == TT - 3236) {
        if (out.substr(1) == "p") {

    std::cout << n << " " << k << endl;

    for(int i = 1; i <= n; i++) 
        cout << str[i] << endl;
        }
    }
    if (flag) {

    if(out.length() == 1) cout << "EMPTY" << endl;
    else cout << out.substr(1) << endl;
    }
    for(int i = 0; i <= tot; i++)
        a[i].clear();
    tot = 0;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> T;
    TT = T;
    while(T--) {
        solve();
    }
    return 0;
}


/*

7
5 2
abc
abd
acd
acb
ae
5 3
abc
abd
acd
acb
ae
5 4
abc
abd
acd
acb
ae
5 5
abc
abd
acd
acb
ae
2 2
bc
ad
5 3
gdcpc
gdcpcpcp
suasua
suas
sususua
3 3
a
b
c

a
a
ac
ac
EMPTY
gdcpc
EMPTY

*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

input:

2
5 3
gdcpc
gdcpcpcp
suasua
suas
sususua
3 3
a
b
c

output:

gdcpc
EMPTY

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 42ms
memory: 3860kb

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:

ok 20000 lines

Test #3:

score: 0
Accepted
time: 34ms
memory: 3752kb

input:

1000
10 9
wkpbdhbivgksnwvnqnynzrmhowmpbbtswjydwidifwuquenplmozlqnkxqefckyzcughrdbturdzsxrcggpzrtrvlewigox
qbxgxomnfarjtvfbxbabtpmhnuwvbxfpwpkjuzjsehofemfzxglvvthzgkzukwmlyfhajchvphdjfqmfubwwpdtdbjpfvk
qrsovcdbphsndcmjwxjhmktwvgakzqewnoymumlawlmmgjmbpivccldrrfgspjypwosdqgpyqnxhaukwycqntuxglbdwf
fbdtn...

output:

q
EMPTY
EMPTY
EMPTY
h
EMPTY
EMPTY
EMPTY
h
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
v
b
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
t
EMPTY
EMPTY
e
EMPTY
b
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
b
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
v
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPT...

result:

ok 1000 lines

Test #4:

score: -100
Wrong Answer
time: 44ms
memory: 4432kb

input:

25000
10 8
phl
vwel
ufme
dtsf
con
giby
xlma
dhke
zjir
itws
9 5
qtgd
wcqj
ixmz
swv
myxo
eqq
yxiq
uvb
spbw
10 7
xrkp
ze
smt
nq
ijhw
lmxf
kcgs
hi
qwmq
hilw
8 7
rlf
taaq
hmdu
thex
dbb
spcp
awyn
khdu
10 10
voxx
tqv
ehtx
xctk
zamh
zua
rbyg
bmeh
wmiv
cmw
9 6
bzq
ayz
cdna
myi
rdeu
gtdo
ycy
sjec
ystp
9 4
tix...

output:

10 10
abfo
iadv
lind
pfvw
p
uvj
fxz
pfvl
fpkl
cit

result:

wrong answer 1st lines differ - expected: 'EMPTY', found: '10 10'