QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#726177 | #6516. New but Nostalgic Problem | _xqy_ | WA | 30ms | 65488kb | C++20 | 1.2kb | 2024-11-08 22:09:14 | 2024-11-08 22:09:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1E6 + 5;
int cnt;
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 = 0;
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 = 0;
while (true) {
int t = sz[now];
for (int i = 0 ; i < 26 ; ++i) {
if (pre[tr[now][i]]) t ++;
}
if (t >= k) {
if (now == 0) 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 = 0;
}
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: 1ms
memory: 5616kb
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: 30ms
memory: 65488kb
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'