正解 TLE 求助
查看原帖
正解 TLE 求助
181276
bifanwen楼主2024/7/22 19:40

不是,这 O(n)\mathcal{O}(n) 的做法,怎么跑出来 T 的啊?

实在想不出来。有大佬可否指点一下。

#include <bits/stdc++.h>
using namespace std;

template <typename T>
inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	while(!isdigit(c)) {if(c == '-') f = -f; c = getchar();}
	while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
	x *= f;
}

const int N = 1e5 + 1;
const int M = (1 << 8);

char s[N], t[N];
int x[M], y[M];

int main() {
	scanf("%s%s", s, t);
	for(int i = 0; i < strlen(s); i++) x[s[i]]++;
	for(int i = 0; i < strlen(t); i++) y[t[i]]++;
	int Ans = 0;
	for(int i = 'a'; i <= 'z'; i++) Ans += min(x[i], y[i]);
	printf("%d\n", Ans);
	return 0;
}

2024/7/22 19:40
加载中...