QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#360943#6787. Seven Segment DisplayXiangmyAC ✓20ms3844kbC++202.2kb2024-03-22 16:20:112024-03-22 16:20:12

Judging History

你现在查看的是最新测评结果

  • [2024-03-22 16:20:12]
  • 评测
  • 测评结果:AC
  • 用时:20ms
  • 内存:3844kb
  • [2024-03-22 16:20:11]
  • 提交

answer

/*
* Author: Xiangmy
* Created: 2024-03-22 11:57
* Problem: 
* Description: 模拟
* 分为 7 ~ i,i,i-1 ~ 0 三段分别计算 i-1 ~ 0 会被加 i 轮
*/
// #pragma GCC optimize(2)
// #pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << (x) << ' '
// #define x first
// #define y second
typedef long long LL;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> PII;

const LL cost[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6, 6, 5, 4, 5, 5, 4};
vector<LL> pre(17);

void init() {
    for (int i = 0; i < 16; ++ i) {
        pre[i + 1] += pre[i] + cost[i];
    }
}

void solve() {
    LL t; cin >> t; string s; cin >> s;
    LL x = 0;
    for (int i = 0; i < 8; ++ i) {  // 16进制转10进制
        x *= 16;
        if (isdigit(s[i])) x += s[i] - '0';
        else x += s[i] - 'A' + 10;
    }

    auto calc = [&](LL n) -> LL {
        LL res = 0;
        if (n == (1ll << 32)) {
            return pre[16] * (1ll << 28) * 8;  // 8位每位都会加16^7次(其他位全排列)
        }
        LL s = 0;
        for (int i = 7; i >= 0; -- i) {
            int d = n >> (4 * i) & 15;  // 第 i 位的值。& 15 只取最后4位
            res += pre[d] * (1ll << (4 * i)); // 第 i 位的值被加了几次
            res += s * d * (1ll << (4 * i));  // 第 7 ~ i+1 位被加的次数
            if (i != 0) {  // i ~ 0 位一共i位被加了几轮
                res += pre[16] * d * (1ll << (4 * (i - 1))) * i;
            }
            s += cost[d];
        }
        return res;
    };

    LL ans = 0;
    LL st = x, ed = x + t;
    if (ed <= (1ll << 32)) {
        ans += calc(ed);
    } else {  // 溢出 FFFFFFFF 的情况
        ans += calc(ed - (1ll << 32));  
        ans += calc(1ll << 32);
    }
    ans -= calc(st);

    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);  // 交互题不用
    cout.tie(0);
    // cout << fixed << setprecision(6);
    // cout << setw(4) << setfill('0');
    init();
    int T = 1;
    cin >> T;
    while (T -- ) {
        // cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
        solve();
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3588kb

input:

3
5 89ABCDEF
3 FFFFFFFF
7 00000000

output:

208
124
327

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 20ms
memory: 3844kb

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