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 | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | 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 |
10 | nor | 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 |
---|