| 比赛 |
2026.8.28 |
评测结果 |
AAAAAAAATA |
| 题目名称 |
败给了性格恶劣的天才青梅 |
最终得分 |
90 |
| 用户昵称 |
RpUtl |
运行时间 |
8.556 s |
| 代码语言 |
C++ |
内存使用 |
10.78 MiB |
| 提交时间 |
2026-08-28 12:37:27 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
struct BigInteger {
static const int BASE = 1000000000;
static const int BASE_DIGITS = 9;
bool neg;
vector<int> d;
BigInteger() : neg(false), d(1, 0) {}
BigInteger(long long x) {
neg = (x < 0);
if (x == 0) d.push_back(0);
else {
x = llabs(x);
while (x) {
d.push_back(x % BASE);
x /= BASE;
}
}
}
void normalize() {
while (d.size() > 1 && d.back() == 0) d.pop_back();
if (d.size() == 1 && d[0] == 0) neg = false;
}
int absCompare(const BigInteger& other) const {
if (d.size() != other.d.size())
return d.size() > other.d.size() ? 1 : -1;
for (int i = d.size() - 1; i >= 0; --i) {
if (d[i] != other.d[i])
return d[i] > other.d[i] ? 1 : -1;
}
return 0;
}
BigInteger abs() const {
BigInteger res = *this;
res.neg = false;
return res;
}
BigInteger operator-() const {
BigInteger res = *this;
if (!(res.d.size() == 1 && res.d[0] == 0))
res.neg = !res.neg;
return res;
}
static BigInteger addAbs(const BigInteger& a, const BigInteger& b) {
BigInteger res;
res.neg = false;
int carry = 0;
size_t maxLen = max(a.d.size(), b.d.size());
res.d.resize(maxLen, 0);
for (size_t i = 0; i < maxLen || carry; ++i) {
if (i == res.d.size()) res.d.push_back(0);
long long sum = carry;
if (i < a.d.size()) sum += a.d[i];
if (i < b.d.size()) sum += b.d[i];
res.d[i] = sum % BASE;
carry = sum / BASE;
}
if (carry) res.d.push_back(carry);
res.normalize();
return res;
}
static BigInteger subAbs(const BigInteger& a, const BigInteger& b) {
BigInteger res;
res.neg = false;
int borrow = 0;
res.d.resize(a.d.size());
for (size_t i = 0; i < a.d.size(); ++i) {
long long sub = a.d[i] - borrow;
if (i < b.d.size()) sub -= b.d[i];
if (sub < 0) {
sub += BASE;
borrow = 1;
} else {
borrow = 0;
}
res.d[i] = sub;
}
res.normalize();
return res;
}
BigInteger& operator+=(const BigInteger& other) {
if (neg == other.neg) {
BigInteger sum = addAbs(*this, other);
sum.neg = neg;
*this = sum;
} else {
int cmp = absCompare(other);
if (cmp == 0) {
*this = BigInteger(0);
} else if (cmp > 0) {
BigInteger diff = subAbs(*this, other);
diff.neg = neg;
*this = diff;
} else {
BigInteger diff = subAbs(other, *this);
diff.neg = other.neg;
*this = diff;
}
}
return *this;
}
BigInteger& operator-=(const BigInteger& other) {
return *this += (-other);
}
BigInteger operator+(const BigInteger& other) const {
BigInteger res = *this;
res += other;
return res;
}
BigInteger operator-(const BigInteger& other) const {
BigInteger res = *this;
res -= other;
return res;
}
BigInteger operator*(long long x) const {
if ((d.size() == 1 && d[0] == 0) || x == 0) return BigInteger(0);
BigInteger res;
res.neg = (neg != (x < 0));
long long absX = llabs(x);
long long carry = 0;
for (size_t i = 0; i < d.size() || carry; ++i) {
if (i == res.d.size()) res.d.push_back(0);
long long prod = carry;
if (i < d.size()) prod += (long long)d[i] * absX;
res.d[i] = prod % BASE;
carry = prod / BASE;
}
res.normalize();
return res;
}
friend BigInteger operator*(long long lhs, const BigInteger& rhs) {
return rhs * lhs;
}
friend ostream& operator<<(ostream& os, const BigInteger& x) {
if (x.neg && !(x.d.size() == 1 && x.d[0] == 0)) os << '-';
os << x.d.back();
for (int i = (int)x.d.size() - 2; i >= 0; --i) {
os << setw(BASE_DIGITS) << setfill('0') << x.d[i];
}
return os;
}
};
const int N = 1e5 + 10;
BigInteger C[85][85], w[N], ans, v[85];
long long n, k, p, a[N];
BigInteger LLabs(const BigInteger& x) {
return x.abs();
}
void write(const BigInteger& x) {
cout << x;
}
int main() {
freopen("defeat.in", "r", stdin);
freopen("defeat.out", "w", stdout);
cin >> n >> k >> p;
C[0][0] = 1;
C[0][1] = 1;
for (int i = 1; i <= p; i++) {
for (int j = 0; j <= p + 1; j++) {
C[i][j] += C[i - 1][j];
if (j) C[i][j] += C[i - 1][j - 1];
}
}
for (int i = 0; i <= p + 1; i++) {
if (i & 1)
v[i] = C[p][i];
else
v[i] = -C[p][i];
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] -= k;
}
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= p + 1; j++) {
if (i + j <= n) {
w[i + j] += a[i] * v[j];
}
}
}
for (int i = 1; i <= n; i++) {
ans += LLabs(w[i]);
}
write(ans);
return 0;
}