QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#699026 | #6516. New but Nostalgic Problem | 0x3fffffff | WA | 31ms | 221944kb | C++23 | 2.6kb | 2024-11-01 23:51:40 | 2024-11-01 23:51:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
struct Tire {
vector<array<int, 26>>ch;
vector<int>siz, cnt;
int idx;
Tire() {
idx = 0;
ch.assign(N, {});
cnt.resize(N);
siz.resize(N);
// pos.resize(N);
}
Tire(int n) {
idx = 0;
ch.assign(n + 1, {});
cnt.resize(n + 1);
siz.resize(n + 1);
// pos.resize(n + 1);
}
int newnode() {
++idx;
fill(ch[idx].begin(), ch[idx].end(), 0);
siz[idx] = cnt[idx] = 0;
return idx;
}
void insert(string& s, int now) {
int p = 0;
for (auto x : s) {
int c = x - 'a';
if (!ch[p][c])ch[p][c] = newnode();
p = ch[p][c];
siz[p]++;
}
// pos[p] = now;
cnt[p]++;
}
int query(string& s) {
int p = 0;
for (auto x : s) {
int c = x - 'a';
if (!ch[p][c])return 0;
p = ch[p][c];
}
return cnt[p];
}
void solve(int k) {
int p = 0;
// auto dfs = [&](auto&& ff, int p)->void {
while (1) {
int sum = cnt[p];
for (int i = 0;i < 26;i++) {
if (siz[ch[p][i]])sum++;
}
if (sum >= k) {
if (p == 0) {
cout << "EMPTY\n";return;
}
return;
}
for (int i = 0;i < 26;i++) {
if (siz[ch[p][i]]) {
sum += siz[ch[p][i]] - 1;
if (sum >= k) {
k -= sum - siz[ch[p][i]];
cout << (char)(i + 'a');
p = ch[p][i];
break;
// ff(ff, ch[p][i]);
}
}
}
};
// dfs(dfs, 0);
// cout << "\n";
}
};
void solve() {
int T;cin >> T;
Tire tr;
while (T--) {
int n, k;cin >> n >> k;
vector<string>s(n + 1);
int mx = 0;
for (int i = 1;i <= n;i++) {
cin >> s[i];
mx = max(mx, (int)s[i].size());
}
for (int i = 1;i <= n;i++) {
tr.insert(s[i], i);
}
tr.solve(k);
cout << "\n";
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int T = 1;
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
// cin >> T;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 221944kb
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: 31ms
memory: 221792kb
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 ...
result:
wrong answer 2nd lines differ - expected: 'EMPTY', found: ''