T2 错误程序但AC,请求修正数据
大体思路:每一个数字对答案的贡献是 ,全部相加再对
取模就是答案,用 Lucas 定理计算组合数的取模:
#include <utility>
#include <cstdio>
using namespace std;
const int MAXN = 200005;
int n;
char str[MAXN];
const int C[4][4] = {{1, 0, 0}, {1, 1, 0}, {1, 2, 1}};
int lucasC(int n, int m)
{
if (n < 3 && m < 3)
return C[n][m];
else
return lucasC(n / 3, m / 3) * C[n % 3][m % 3] % 3;
}
int arr[MAXN];
inline void solve()
{
int tot = 0;
for (int i = 1; i <= n; i++)
{
arr[i] = (3 - (str[i] - 'A')) % 3;
arr[i] = arr[i] * lucasC(n - 1, i - 1) % 3;
tot = (tot + arr[i]) % 3;
}
printf("%c\n", tot + 'A');
}
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
scanf("%s", str + 1);
solve();
}
return 0;
}
给的样例都过不了,本地对拍也是全挂,但是提交可以 AC(记录)。
其实正确解法只要改一处,就是把 arr
的预处理中用 减给去掉,在输出答案时根据
的奇偶性来判断
tot
是否取相反数(记录)。
hack 也很简单,只要让 为奇数即可,推测评测数据里
全开到最大导致全是偶数。