#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int>>
using namespace std;
void solve(){
int n,k,m;
string s;
cin >> n >> k >> m >> s;
string out;
int cnt[k] = {};
int total = 0;
for(int i=0;i<m;i++){
bool good = true;
if(s[i] < 'a'+k){
cnt[s[i]-'a']++;
}
for(int j=0;j<k;j++){
if(cnt[j]<1){
good = false;
break;
}
}
if(!good) continue;
out.pb(s[i]);
for(int j=0;j<k;j++){
cnt[j] = 0;
}
total++;
}
if(total>=n){
cout << "YES\n";
return;
}
cout << "NO\n";
cout << out;
for(int i=0;i<k;i++){
if(cnt[i]==0){
for(int j=0;j<n-out.size();j++){
cout << (char)('a'+i);
cout << "\n";
return;
}
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
return 0;
}
Took me way more than I'd like, I wasn't able to find any error on the logic, because it's right!. I even had to bruteforce getting the test case to find out the problem and it's absolutely silly.
If the answer is NO, you also need to print a string of length n
And you aren't doing that because of your return.
I wanna cry
I'm dumb asf, I can't wait till I get better at debugging(or just not making these dumb mistakes in the first place) any tips on that?
I don't know either, I spent around an hour trying to come up with a test case or find where it was failing but I couldn't. At the end I surrendered and got the test case from the problem.
You can make a submission that outputs the test case 140 so you can see it. Just to be clear, the logic should be something like if the number of test cases is bigger than 140, dont print the output, just print the test case you are interested in.
But isn't that test case hidden behind the "..."?
Example of how to do that: 283950709