Editorial for Bedao Grand Contest 03 - STRCOM
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Code mẫu
#include <bits/stdc++.h> using namespace std; const int N = 105; int m, k, cnt[N][26]; string s, t; vector<int> ve; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); freopen("STRCOM.inp", "r", stdin); freopen("STRCOM.out", "w", stdout); cin >> m >> k >> s; while (m--) { cin >> t; int n = t.size(), ans = 0; ve.clear(); for (int i = 0; i < n; i++) { for (int j = 0; j < 26; j++) { cnt[i][j] = 0; } } for (int i = 0; i < s.size(); i++) { cnt[i % n][s[i] - 'a']++; } for (int i = 0; i < n; i++) { ans += cnt[i][t[i] - 'a']; ve.push_back(*max_element(cnt[i], cnt[i] + 26) - cnt[i][t[i] - 'a']); } sort(ve.begin(), ve.end(), greater<int>()); if (k > ve.size()) { ans += accumulate(ve.begin(), ve.end(), 0); } else { ans += accumulate(ve.begin(), ve.begin() + k, 0); } cout << s.size() - ans << '\n'; } }
Comments