QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#321419 | #6787. Seven Segment Display | iee | AC ✓ | 26ms | 3664kb | C++17 | 1.0kb | 2024-02-04 17:33:27 | 2024-02-04 17:33:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int cost[16] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6, 6, 5, 4, 5, 5, 4}, pre[17];
constexpr int up = 1ll << 32;
int solve(int n) {
if (n == up) {
return 8 * (1ll << 28) * pre[16];
}
int res = 0, s = 0;
for (int i = 7; i >= 0; i--) {
int d = n >> (i * 4) & 15;
res += s * d * (1ll << (4 * i));
res += pre[d] * (1ll << (4 * i));
if (i) {
res += d * i * pre[16] * (1ll << (4 * (i - 1)));
}
s += cost[d];
}
return res;
}
void solve() {
int n;
cin >> n;
int a = 0;
for (int i = 0; i < 8; i++) {
a *= 16;
char c;
cin >> c;
if (isdigit(c)) {
a += c - '0';
} else {
a += 10 + c - 'A';
}
}
int r = a + n;
if (r >= up) {
cout << solve(r - up) + solve(up) - solve(a) << "\n";
} else {
cout << solve(r) - solve(a) << "\n";
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
for (int i = 0; i < 16; i++) {
pre[i + 1] = pre[i] + cost[i];
}
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3664kb
input:
3 5 89ABCDEF 3 FFFFFFFF 7 00000000
output:
208 124 327
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 26ms
memory: 3664kb
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