C. Digital Logarithm
https://codeforces.com/contest/1728/problem/C
模拟题
inline void solve() {
int n;
cin >> n;
multiset<int> a, b;
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
a.insert(t);
}
for (int i = 0; i < n; ++i) {
int t;
cin >> t;
b.insert(t);
}
list<int> ls;
for (auto x : a) {
if (b.find(x) != b.end()) {
b.erase(b.find(x));
ls.push_back(x);
}
}
while (!ls.empty()) {
a.erase(a.find(ls.back()));
ls.pop_back();
}
auto getBits = [](int x) {
int res = 0;
while (x) {
x /= 10;
res ++;
}
return res;
};
map<int, multiset<int>> ma, mb;
for (auto x : a) {
int t = getBits(x);
ma[t].insert(x);
}
for (auto x : b) {
int t = getBits(x);
mb[t].insert(x);
}
int ans = 0;
auto cal = [&ls, &getBits, &ans](multiset<int>& l, multiset<int>& r, map<int, multiset<int>>& ml, map<int, multiset<int>>& mr) {
for (auto x : l) {
if (x < 2 || x > 9) {
continue;
}
if (!mr[x].empty()) {
auto f = *mr[x].begin();
mr[x].erase(mr[x].begin());
ls.push_back(x);
r.erase(r.find(f));
}
}
ans += ls.size();
while (!ls.empty()) {
auto x = ls.back();
l.erase(l.find(x));
ls.pop_back();
auto t = getBits(x);
ml[t].erase(ml[t].find(x));
}
};
cal(a, b, ma, mb);
cal(b, a, mb, ma);
for (int i = 2; i < 10; ++i) {
int maxn = max(ma[i].size(), mb[i].size());
ans += 2 * maxn;
}
ans += ma[1].size() + mb[1].size();
ans -= ma[1].count(1) + mb[1].count(1);
cout << ans << '\n';
}

浙公网安备 33010602011771号