QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#373667#6787. Seven Segment DisplayXiangmyAC ✓1827ms4132kbC++201.7kb2024-04-01 21:40:212024-04-01 21:40:22

Judging History

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

  • [2024-04-01 21:40:22]
  • 评测
  • 测评结果:AC
  • 用时:1827ms
  • 内存:4132kb
  • [2024-04-01 21:40:21]
  • 提交

answer

/*
* Author: Xiangmy
* Created: 2024-04-01 20:11
* Problem: 
* Description: 
*/
#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;
const int N = 200;
typedef pair<int, int> PII;

vector<int> num(N);
LL dp[N][N];

LL mp[] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6, 6, 5, 4, 5, 5, 4};

LL dfs(int pos, LL v, bool limit) {
    if (pos == 0) return v;
    if (!limit && dp[pos][v] != -1) return dp[pos][v];
    LL res = 0;
    int up = (limit ? num[pos] : 15);
    for (int i = 0; i <= up; ++ i) {
        res += dfs(pos - 1, v + mp[i], limit && i == up);
    }
    if (!limit) dp[pos][v] = res;
    return res;
}

LL work(LL x) {
    for (int i = 1; i <= 8; ++ i) {
        num[i] = x % 16;
        x /= 16;
    }
    memset(dp, -1, sizeof dp);
    return dfs(8, 0, true);
}

void solve() {
    LL t; string s; cin >> t >> s;
    LL st = 0;
    for (int i = 0; i <= 7; ++ i) {
        st *= 16;
        if (isdigit(s[i])) st += s[i] - '0';
        else st += s[i] - 'A' + 10;
    }
    LL ed = st + t - 1;
    LL ans = 0;
    if (ed <= (1ll << 32) - 1) {
        ans += work(ed);
    } else {
        ans += work(ed % (1ll << 32));
        ans += work((1ll << 32) - 1);
    }
    ans -= work(st - 1);
    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');
    
    int T = 1;
    cin >> T;
    while (T -- ) {
        // cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
        solve();
    }
    return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 4132kb

input:

3
5 89ABCDEF
3 FFFFFFFF
7 00000000

output:

208
124
327

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1827ms
memory: 3908kb

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