QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#398121#6516. New but Nostalgic ProblemiwewWA 18ms3864kbC++201.7kb2024-04-24 22:30:432024-04-24 22:30:45

Judging History

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

  • [2024-04-24 22:30:45]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3864kb
  • [2024-04-24 22:30:43]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int N = 1e6 + 10;

int n, K, idx;

struct Node {
    int cnt, ch[26];
}tr[N];

void insert(string s) {
    int cur = 0;
    for(auto c : s) {
        if(!tr[cur].ch[c - 'a']) {
            tr[cur].ch[c - 'a'] = ++ idx;
        }
        tr[tr[cur].ch[c - 'a']].cnt += 1;
        cur = tr[cur].ch[c - 'a'];
    }
}

void query(string &ans, int K) {
    tr[0].cnt = n;
    int cur = 0;
    while(true) {
        int cnt = 0;
        for(int i = 0; i < 26; i ++ ) {
            if(tr[cur].ch[i]) {
                cnt ++ ;
            }
        }

        bool ok = false;
        for(int i = 0; i < 26; i ++ ) {
            if(tr[cur].ch[i] && tr[tr[cur].ch[i]].cnt >= 2) {
                if(tr[tr[cur].ch[i]].cnt + cnt - 1 >= K) {
                    ans += (char)(i + 'a');
                    K -= cnt - 1, cur = tr[cur].ch[i];
                    ok = true;
                    break;
                } else {
                    cnt = cnt - 1 + tr[tr[cur].ch[i]].cnt;
                }
            }
        }

        if(!ok) break;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int T;
    cin >> T;
    while(T -- ) {
        cin >> n >> K;
        for(int i = 0; i < n; i ++ ) {
            string s;
            cin >> s;
            insert(s);
        }

        string ans;
        query(ans, K);
        if(!ans.empty()) cout << ans << '\n';
        else cout << "EMPTY" << '\n';

        for(int i = 0; i <= idx; i ++ ) {
            tr[i].cnt = 0;
            for(int j = 0; j < 26; j ++ ) {
                tr[i].ch[j] = 0;
            }
        }
        idx = 0;
    }
    return 0;
}

詳細信息

Test #1:

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

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: 18ms
memory: 3864kb

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
t
EMPTY
EMPTY
m
EMPTY
a
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
e
r
EMPTY
o
v
EMPTY
w
EMPTY
EMPTY
t
EMPTY
s
z
v
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
w
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
w
u
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPT...

result:

wrong answer 13th lines differ - expected: 'EMPTY', found: 't'