QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#726187 | #6516. New but Nostalgic Problem | _xqy_ | WA | 24ms | 66108kb | C++20 | 1.2kb | 2024-11-08 22:11:43 | 2024-11-08 22:11:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1E6 + 5;
int cnt = 1;
int tr[N][26] , pre[N] , sz[N];
void solve() {
int n,k;
cin >> n >> k;
auto add = [&] (string s) {
int m = s.size() , now = 1;
pre[now] += 1;
for (int i = 0 ; i < m ; ++i) {
int x = s[i] - 'a';
if (!tr[now][x]) tr[now][x] = ++cnt;
now = tr[now][x];
pre[now] += 1;
}
sz[now] += 1;
};
for (int i = 0 ; i < n ; ++i) {
string s;
cin >> s;
add(s);
}
int now = 1;
while (true) {
int t = sz[now];
for (int i = 0 ; i < 26 ; ++i) {
if (pre[tr[now][i]]) t ++;
}
if (t >= k) {
if (now == 1) cout << "EMPTY\n";
else cout << "\n";
return;
}
for (int i = 0 ; i < 26 ; ++i) {
if (pre[tr[now][i]]) {
t = t - 1 + pre[tr[now][i]];
if (t >= k) {
k -= (t - pre[tr[now][i]]);
now = tr[now][i];
cout << char(i + 'a');
break;
}
}
}
}
for (int i = 0 ; i <= cnt ; ++i) {
pre[cnt] = sz[cnt] = 0;
for (int j = 0 ; j < 26 ; ++j) {
tr[cnt][j] = 0;
}
}
cnt = 1;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
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: 5632kb
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: 24ms
memory: 66108kb
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 EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY EMPTY ...
result:
wrong answer 3rd lines differ - expected: 'w', found: 'EMPTY'