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 | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
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 |
---|