QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#429069 | #6516. New but Nostalgic Problem | dnialh# | TL | 0ms | 3512kb | C++20 | 2.9kb | 2024-06-02 00:28:37 | 2024-06-02 00:28:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define sq(a) ((a)*(a))
#define MOO(i,a,b) for (int i=a; i<b; i++)
#define M00(i,a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)
#define per(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a,b) for (int i=a; i<b; i++)
#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<a; i++)
#define ROF(i,a,b) for (int i = (b)-1; i >= a; i--)
#define R0F(i,a) for (int i = (a)-1; i >= 0; i--)
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << endl, 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << endl;
#define _ << " _ " <<
template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ld,ld> pld;
typedef complex<ld> cd;
typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;
const ld PI = acos(-1.0);
const ld EPS = 1e-7;
const int MOD = 1e9+7;
struct tnode {
char c;
int here;
tnode* next[26];
int cnt[26];
tnode() {
c = ' ';
here = 0;
M00(i, 26) next[i] = nullptr;
M00(i, 26) cnt[i] = 0;
}
};
void addToTrie(string s, tnode* root) {
tnode* cur = root;
for(char ch: s) {
int idx = ch - 'a';
if(cur->next[idx] == nullptr) {
cur->next[idx] = new tnode();
}
cur->cnt[idx]++;
cur = cur->next[idx];
cur->c = ch;
}
cur->here += 1;
}
int unique(tnode* root) {
int ans = root->here;
M00(i, 26) ans += (root->cnt[i] > 0);
return ans;
}
void free_trie(tnode* root) {
if(root == nullptr) return;
M00(i, 26) {
free_trie(root->next[i]);
}
delete root;
}
void solve() {
tnode* root = new tnode();
int n, k; cin >> n >> k;
vector<string> arr(n);
M00(i, n) cin >> arr[i];
M00(i, n) addToTrie(arr[i], root);
tnode* rroot = root;
vector<char> ans;
while(true) {
if(unique(root) >= k) {
if(ans.size() == 0) {
cout << "EMPTY";
} else {
for(auto &s : ans) cout << s;
}
cout << '\n';
free_trie(rroot);
return;
}
k -= root->here;
int next = 0;
int before = 0;
M00(i, 26) next += (root->cnt[i] > 0);
M00(i, 26) {
next -= root->cnt[i] > 0;
int poss = root->cnt[i] + next + before;
if(poss >= k) {
ans.pb('a' + i);
k -= next;
root = root->next[i];
break;
}
before += root->cnt[i];
}
}
}
int32_t main() { FAST
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int t; cin >> t;
while(t--) solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
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
Time Limit Exceeded
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...