QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#222569#6516. New but Nostalgic Problemkabuu#WA 25ms5900kbC++201.6kb2023-10-21 17:38:392023-10-21 17:38:40

Judging History

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

  • [2023-10-21 17:38:40]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:5900kb
  • [2023-10-21 17:38:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

const int N = 1E6 + 1000;

int nxt[N][26], siz[N];

int tot;

int newNode() {
	++tot;
	for (int i = 0; i < 26; i++) {
		nxt[tot][i] = 0;
	}
	siz[tot] = 0;
	return tot;
}

void solve() {
	int n, k;
    cin >> n >> k;

    tot = 0;
    siz[tot] = 0;
    newNode();
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        int p = 1;
        siz[p]++;
        for (int j = 0; j < s[i].size(); j++) {
            if (!nxt[p][s[i][j] - 'a']) {
                nxt[p][s[i][j] - 'a'] = newNode();
            }
            p = nxt[p][s[i][j] - 'a'];
            siz[p]++;
        }
    }

    int p = 1;
    string ans;
    while (true) {
        vector<int> suf(27);
        for (int i = 25; i >= 0; i--) {
            suf[i] = suf[i + 1] + (siz[nxt[p][i]] > 0);
        }

        int s = 0, id = -1;
        for (int i = 0; i < 26; i++) {
            if (s + siz[nxt[p][i]] + suf[i + 1] >= k) {
                k -= s + suf[i + 1];
                id = i;
                break;
            }
            s += siz[nxt[p][i]];
        }

        if (id == -1) {
            break;
        }

        if (k >= 2) {
            ans += char('a' + id);
            p = nxt[p][id];
        } else {
            break;
        }
    }
    if (ans.empty()) {
        cout << "EMPTY\n";
    } else {
        cout << ans << "\n";
    }
}

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

    int t;
    cin >> t;

    while (t--) {
        solve();
    }

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 20ms
memory: 5892kb

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: 13ms
memory: 5900kb

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: 25ms
memory: 5640kb

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:

EMPTY
EMPTY
EMPTY
EMPTY
z
EMPTY
EMPTY
s
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
y
EMPTY
EMPTY
a
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
m
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
g
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
j
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
j
EMPTY
t
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
EMPTY
...

result:

wrong answer 3236th lines differ - expected: 'pfv', found: 'p'