思路
不难看出只要用杨辉三角计算出 的值,然后找出 有多少个 即可。
恭喜你,获得 分!
其实只要用前缀和维护后半部分,就能得到 分的好成绩。
solution
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define For(i,a,b) for(int i = a;i<=b;i++)
#define Rof(i,a,b) for(int i = a;i>=b;i--)
using namespace std;
int a[5][15005], b[15005], h[40005], n, m;
int main()
{
cin >> n >> m;
if (n <= 10)
{
for (int i = 1; i <= m; i++)
cout << "0 0 0 0" << endl;
return 0;
}
for (int i = 1; i <= m; i++)
{
cin >> h[i];
b[h[i]]++;
}
for (int i = 1; i <= n / 9; i++)
{
int x = 1 + 9 * i, y = 0;
for (int j = 2 + 9 * i; j <= n; j++)
{
y += b[j - x] * b[j - x + i + i];
a[3][j] += y * b[j - i];
a[2][j - i] += y * b[j];
}
x = 8 * i + 1, y = 0;
for (int j = n - 9 * i - 1; j >= 1; j--)
{
y += b[j + x] * b[j + x + i];
a[0][j] += y * b[j + i + i];
a[1][j + i + i] += y * b[j];
}
}
for (int i = 1; i <= m; i++)
{
cout << a[0][h[i]] << " ";
cout << a[1][h[i]] << " ";
cout << a[2][h[i]] << " ";
cout << a[3][h[i]] <<"\n";
}
return 0;
}