Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
37078 | 沈仲恩 | 【S】T1 | C++ | 解答错误 | 64 | 7 MS | 264 KB | 1272 | 2025-03-02 15:33:07 |
#include <bits/stdc++.h> #define int long long using namespace std; int c, n; int frc[16]; signed main() { int c; frc[0] = 1; for (int i = 1; i <= 15; i++) frc[i] = frc[i - 1] * i; scanf("%lld", &c); scanf("%lld", &n); while (n--) { // if (c != 1) // puts("0"); // else // { int x, a, b, c, d; scanf("%lld %lld %lld %lld %lld", &x, &a, &b, &c, &d); int ans = 0x3f3f3f3f3f3f3f3f; for (int i = 0; i < (1 << 13); i++) { int j = 0, tot = 0, tg = 0; int ii = i; while (ii) { j = __lg(ii & (-ii)) + 3; tg += j; ii -= (ii & (-ii)); tot += frc[j]; if (tot > x) break; } if (tot > x) continue; int xx = x - tot, xxx; int lt = xx & 3; xx -= lt; xxx = xx; int cc = 0; while (xxx) { cc += __lg(xxx & (-xxx)); xxx -= xxx & (-xxx); } int h = 0; if (lt & 1) h += min(a + b, c); if (lt & 2) h += min(a + 2 * b, c + d); ans = min(ans, __builtin_popcount(i) * a + b * tg + __builtin_popcount(xx) * c + cc * d + h); } printf("%lld\n", ans); // } } }