比赛 EYOI与SBOI开学欢乐赛10th 评测结果 AAAAAAAAAA
题目名称 数字对数 最终得分 100
用户昵称 HeSn 运行时间 1.601 s
代码语言 C++ 内存使用 5.78 MiB
提交时间 2022-10-10 19:52:09
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1010;
int n, a[MAXN], b[MAXN], cnt, sum1[MAXN], sum2[MAXN], num[MAXN], ans;
map<int, int>mp;
signed main() {
	freopen("numlg.in", "r", stdin);
	freopen("numlg.out", "w", stdout);
	int t;
	cin >> t;
	for(int tt = 1; tt <= t; tt ++) {
		cin >> n;
		mp.clear();
		cnt = 0;
		ans = 0;
		memset(sum1, 0, sizeof(sum1));
		memset(sum2, 0, sizeof(sum2));
		for(int i = 1; i <= n; i ++) {
			cin >> a[i];
			if(!mp[a[i]]) {
				mp[a[i]] = ++ cnt;
				num[cnt] = a[i];
			}
			a[i] = mp[a[i]];
			sum1[a[i]] ++;
		}
		for(int i = 1; i <= n; i ++) {
			cin >> b[i];
			if(!mp[b[i]]) {
				mp[b[i]] = ++ cnt;
				num[cnt] = b[i];
			}
			b[i] = mp[b[i]];
			if(sum1[b[i]]) {
				sum1[b[i]] --;
			}
			else {
				sum2[b[i]] ++;
			}
		}
//		cout << ans << "     ";
		for(int i = 1; i <= cnt; i ++) {
			if(sum1[i]) {
				int x = num[i];
				if(x >= 10) {
					ans += sum1[i];
					int w = (int)log10(x) + 1;
					if(!mp[w]) {
						mp[w] = ++ cnt;
						num[cnt] = w;
					}
					w = mp[w];
					sum1[w] += sum1[i];
					sum1[i] = 0;
				}
			}
		}
		for(int i = 1; i <= cnt; i ++) {
			if(sum2[i]) {
				int x = num[i];
				if(x >= 10) {
					ans += sum2[i];
					int w = (int)log10(x) + 1;
					if(!mp[w]) {
						mp[w] = ++ cnt;
						num[cnt] = w;
					}
					w = mp[w];
					sum2[w] += sum2[i];
					sum2[i] = 0;
				}
			}
		}
//		cout << ans << "     ";
		for(int i = 1; i <= cnt; i ++) {
			int w = min(sum1[i], sum2[i]);
			sum1[i] -= w;
			sum2[i] -= w;
		}
		for(int i = 1; i <= cnt; i ++) {
			if(num[i] == 1) {
				continue;
			}
			ans += sum1[i] + sum2[i];
		}
		cout << ans << endl;
	}
	return 0;
}