I hate be the guy that spams questioning blogs but... On the problem, Did We Get Everything Covered?, I did the solution but in reverse kind of. Just look at my code and you'll see what I mean, but something is wrong. What?
Code
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 170 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 160 |
5 | djm03178 | 158 |
5 | -is-this-fft- | 158 |
7 | adamant | 154 |
7 | Dominater069 | 154 |
9 | awoo | 153 |
10 | luogu_official | 152 |
Failing to build a greedy countercase
I hate be the guy that spams questioning blogs but... On the problem, Did We Get Everything Covered?, I did the solution but in reverse kind of. Just look at my code and you'll see what I mean, but something is wrong. What?
#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;
}
Rev. | Lang. | By | When | Δ | Comment | |
---|---|---|---|---|---|---|
en4 | Negationist | 2024-10-01 23:17:09 | 8 | |||
en3 | Negationist | 2024-10-01 21:56:21 | 41 | Tiny change: 'oiler>\n\n\n' -> 'oiler>\n\nEdit: I failed test case 140 in test 2.\n\n' | ||
en2 | Negationist | 2024-10-01 21:54:50 | 3 | Tiny change: 'I hate be the guy t' -> 'I hate being the guy t' | ||
en1 | Negationist | 2024-10-01 21:06:32 | 1575 | Initial revision (published) |
Name |
---|