QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#184115 | #6787. Seven Segment Display | ucup-team004# | AC ✓ | 20ms | 3860kb | C++20 | 1.4kb | 2023-09-20 13:08:31 | 2023-09-20 13:08:31 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
constexpr int cost[16] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6, 6, 5, 4, 5, 5, 4};
int pre[17];
i64 get(i64 n) {
if (n == (1LL << 32)) {
return pre[16] * (1LL << 28) * 8;
}
i64 ans = 0;
int s = 0;
for (int i = 7; i >= 0; i--) {
int d = n >> (4 * i) & 15;
ans += pre[d] * (1LL << (4 * i));
ans += 1LL * s * d * (1LL << (4 * i));
if (i) {
ans += 1LL * pre[16] * d * (1LL << (4 * i - 4)) * i;
}
s += cost[d];
}
return ans;
}
void solve() {
int n;
std::cin >> n;
std::string s;
std::cin >> s;
i64 a = 0;
for (int i = 0; i < 8; i++) {
a *= 16;
if (std::isdigit(s[i])) {
a += s[i] - '0';
} else {
a += s[i] - 'A' + 10;
}
}
i64 ans = 0;
i64 l = a, r = l + n;
if (r <= (1LL << 32)) {
ans += get(r);
} else {
ans += get(r - (1LL << 32));
ans += get(1LL << 32);
}
ans -= get(l);
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
for (int i = 0; i < 16; i++) {
pre[i + 1] = pre[i] + cost[i];
}
int t;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
3 5 89ABCDEF 3 FFFFFFFF 7 00000000
output:
208 124 327
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 20ms
memory: 3860kb
input:
100000 9364638 AAFC2B35 429015486 47932346 419450064 A2ECB537 658945285 AD0E13E5 34841526 5ABD7876 385322997 E143180D 868762739 1086F8F3 45102799 2F1F9E5E 771587735 CC208792 758215026 9B636EE1 149844 FF4A6462 511247023 D9B7E4D6 453286898 69CB52CE 54578400 3C4F80F1 478112641 EFE86CC5 510676410 CF6EBA...
output:
375365926 16710737387 16682763892 25517899397 1357311411 14889613447 33099449396 1733912645 29937149005 29815022146 5478309 19819765288 17425826897 2122741445 18661043864 19976724262 26653518739 4946797240 19424648416 23012420629 11669715958 32307045060 2729333803 29952429156 28759096349 17083767159...
result:
ok 100000 lines