QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#254178#6621. Luggage Lockucup-team1769#AC ✓12ms4788kbC++202.4kb2023-11-18 03:27:002023-11-18 03:27:01

Judging History

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

  • [2023-11-18 03:27:01]
  • 评测
  • 测评结果:AC
  • 用时:12ms
  • 内存:4788kb
  • [2023-11-18 03:27:00]
  • 提交

answer

#include <bits/stdc++.h>
bool vis[10][10][10][10];
int a[5],b[5];
int f[10][10][10][10];

struct node{
    int A,B,C,D;
    int cnt;
};

void bfs()
{
    std::queue<node> q;
    q.push({0,0,0,0,0});
    while(!q.empty())
    {
        auto now=q.front();q.pop();
        if(vis[now.A][now.B][now.C][now.D])  continue;
        vis[now.A][now.B][now.C][now.D]=true;
        f[now.A][now.B][now.C][now.D]=now.cnt;
        q.push({(now.A+1)%10,now.B,now.C,now.D,now.cnt+1});
        q.push({(now.A+9)%10,now.B,now.C,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B+1)%10,now.C,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B+9)%10,now.C,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B)%10,(now.C+1)%10,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B)%10,(now.C+9)%10,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B)%10,(now.C)%10,(now.D+1)%10,now.cnt+1});
        q.push({(now.A)%10,(now.B)%10,(now.C)%10,(now.D+9)%10,now.cnt+1});
        q.push({(now.A+1)%10,(now.B+1)%10,now.C,now.D,now.cnt+1});
        q.push({(now.A+9)%10,(now.B+9)%10,now.C,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B+1)%10,(now.C+1)%10,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B+9)%10,(now.C+9)%10,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B)%10,(now.C+1)%10,(now.D+1)%10,now.cnt+1});
        q.push({(now.A)%10,(now.B)%10,(now.C+9)%10,(now.D+9)%10,now.cnt+1});
        q.push({(now.A+1)%10,(now.B+1)%10,(now.C+1)%10,now.D,now.cnt+1});
        q.push({(now.A+9)%10,(now.B+9)%10,(now.C+9)%10,now.D,now.cnt+1});
        q.push({(now.A)%10,(now.B+1)%10,(now.C+1)%10,(now.D+1)%10,now.cnt+1});
        q.push({(now.A)%10,(now.B+9)%10,(now.C+9)%10,(now.D+9)%10,now.cnt+1});
        q.push({(now.A+1)%10,(now.B+1)%10,(now.C+1)%10,(now.D+1)%10,now.cnt+1});
        q.push({(now.A+9)%10,(now.B+9)%10,(now.C+9)%10,(now.D+9)%10,now.cnt+1});
    }
}

void solve() {
    std::string x,y;
    std::cin>>x>>y;
    a[1]=x[0]-'0',a[2]=x[1]-'0',a[3]=x[2]-'0',a[4]=x[3]-'0';
    b[1]=y[0]-'0',b[2]=y[1]-'0',b[3]=y[2]-'0',b[4]=y[3]-'0';
    for(int i=1;i<=4;++i)
    {
        b[i]=(b[i]-a[i]+10)%10;
    }
    // bfs();
    std::cout<<f[b[1]][b[2]][b[3]][b[4]]<<"\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int t;
    std::cin >> t;
    bfs();
    while (t--) {
        solve();
    }
    return 0;
}

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

詳細信息

Test #1:

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

input:

6
1234 2345
1234 0123
1234 2267
1234 3401
1234 1344
1234 2468

output:

1
1
4
5
1
4

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 7ms
memory: 4648kb

input:

100000
9138 9251
0887 4577
2745 6294
6883 1197
8654 2502
7867 7941
7505 2717
1497 7726
3337 8042
2767 8782
5311 4368
9711 6229
7105 8101
3553 6673
6544 7940
8848 8920
1458 6315
4605 2931
5505 7310
5963 4765
7625 0418
4049 0136
2078 6899
3339 1080
2276 6814
4249 4182
1861 0824
8975 8926
6447 6965
226...

output:

3
6
6
8
9
7
6
7
10
9
6
8
5
4
8
5
8
7
9
4
8
8
8
6
8
5
7
5
7
5
7
7
6
8
4
10
6
5
6
7
7
7
4
7
8
6
5
9
7
6
7
11
10
10
7
5
6
5
7
6
7
9
5
5
6
6
8
5
7
9
10
6
10
5
6
7
6
6
8
6
8
7
7
8
7
8
6
7
6
5
5
6
6
5
7
5
9
6
7
7
7
9
6
9
5
5
8
10
7
3
5
6
7
9
8
6
6
7
10
5
5
6
9
8
6
8
6
5
7
6
11
5
9
6
7
5
10
7
5
8
9
8
7
7
7...

result:

ok 100000 numbers

Test #3:

score: 0
Accepted
time: 12ms
memory: 4788kb

input:

100000
9858 8095
5633 8247
7807 5071
8866 7889
5514 6684
8306 0389
7596 6446
4524 5643
6468 8305
0785 8831
5956 2146
7220 7908
0962 8309
7774 1534
3560 7810
8074 4999
3749 2452
6714 3339
0234 7385
0496 5276
3726 5829
2534 4590
2971 0686
2855 5324
2894 6769
4659 4721
9146 2348
9167 6160
5334 3586
811...

output:

8
9
9
4
4
7
5
3
8
8
6
3
6
8
6
9
6
8
8
5
5
6
8
7
9
6
5
6
7
7
5
7
7
6
9
8
9
4
7
6
5
3
6
6
7
8
10
5
7
8
2
5
4
6
4
5
8
9
4
5
7
5
8
5
5
8
6
6
6
9
8
6
5
5
8
8
6
6
9
4
4
6
5
8
7
6
7
6
6
5
7
6
8
5
11
4
6
8
4
7
7
8
9
10
7
7
6
7
8
6
6
5
7
5
5
5
4
8
9
8
8
7
9
8
8
5
9
4
5
7
8
8
6
8
6
8
5
7
8
7
6
3
7
9
2
4
9
8
6...

result:

ok 100000 numbers

Test #4:

score: 0
Accepted
time: 11ms
memory: 4664kb

input:

100000
9488 6804
6451 0373
5506 4831
6036 2853
4745 5956
0213 1322
0425 3480
8524 2110
7050 1974
4508 8431
6912 5256
4697 8971
9601 1560
1826 8308
2312 4485
7595 5232
2845 0945
9488 4570
8182 2910
8014 8711
4542 4871
4145 3048
0974 7483
5613 8436
7823 5398
4194 5108
4676 7109
1100 7861
3646 9977
030...

output:

8
7
6
9
2
2
8
9
9
8
5
9
6
7
8
6
3
8
10
6
4
4
7
8
7
5
5
6
6
6
10
4
6
6
8
5
7
4
5
3
7
9
7
6
8
6
6
4
10
8
6
8
5
3
7
3
5
6
9
7
7
5
9
4
9
8
5
7
4
6
2
5
5
4
6
3
7
8
7
7
3
4
8
7
7
10
4
5
6
8
9
9
7
6
8
7
7
8
8
8
5
3
8
7
9
7
6
7
3
8
8
6
6
9
7
8
9
3
8
4
5
9
6
4
9
9
5
5
7
5
7
8
7
8
4
9
5
7
9
6
9
6
7
7
7
11
6
9...

result:

ok 100000 numbers

Test #5:

score: 0
Accepted
time: 5ms
memory: 4592kb

input:

100000
7977 1861
4178 8550
4176 3296
9067 3624
3371 4124
7903 9441
8117 4963
8003 4347
4371 4755
0955 8419
9896 9497
7866 5905
0265 6409
6503 1506
6615 2306
3772 9102
2154 8926
2758 4981
0039 2755
5620 2032
3554 2770
4282 6588
3380 1931
5161 5464
2204 6165
4761 3382
5888 9509
8673 2579
9480 5439
887...

output:

9
8
3
6
8
7
7
7
8
7
5
7
8
8
5
6
7
3
10
8
7
7
6
6
9
6
7
9
9
7
10
7
8
8
5
5
5
7
9
4
5
7
6
6
5
5
6
7
10
5
8
6
4
5
7
8
7
6
5
5
9
6
7
6
6
6
4
6
6
3
5
7
9
2
3
7
5
4
7
3
9
6
6
7
7
7
9
6
8
5
8
7
8
10
9
9
9
5
6
8
6
7
7
9
10
7
7
5
8
3
5
6
5
7
7
8
8
6
4
8
5
6
9
7
8
8
4
6
7
8
7
10
7
5
9
7
9
3
5
7
5
8
6
7
7
8
4
...

result:

ok 100000 numbers

Test #6:

score: 0
Accepted
time: 11ms
memory: 4560kb

input:

100000
6700 8700
7657 1240
2505 5812
7989 1758
0801 9714
5968 7812
2361 4954
6420 1616
9945 9162
3897 0314
4576 0783
3907 1462
1180 6105
2947 5838
1063 8541
3627 2118
4743 6624
8841 6903
8072 9021
1568 8778
0129 0048
8895 1343
7871 2171
6815 2775
3595 7701
7874 6619
2681 2825
3748 9138
8188 5967
051...

output:

2
9
6
7
4
8
9
9
5
8
9
6
10
5
5
6
5
8
6
5
4
7
5
7
8
6
4
6
3
8
5
6
7
6
6
5
8
6
8
8
7
8
4
7
3
7
7
7
7
5
8
5
6
7
8
6
8
5
7
3
9
5
8
6
4
6
6
3
6
7
6
3
7
5
7
7
10
5
9
7
9
5
7
2
7
10
6
7
9
7
7
6
6
4
7
7
8
7
6
6
6
8
2
3
8
7
6
6
7
6
6
8
7
5
5
4
6
6
8
8
6
3
5
8
6
6
4
4
8
6
10
2
7
5
8
7
6
4
6
5
7
6
8
4
7
7
7
6
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 7ms
memory: 4572kb

input:

100000
4778 8595
7951 1788
9065 5259
0708 6871
5857 1931
4615 7331
8197 2913
9803 4977
7643 3927
2170 6996
6322 1248
1850 7024
1479 7764
2698 8873
2587 6303
7246 3319
2683 6408
6579 2753
2478 8663
3328 0613
7644 4928
8435 4719
1101 7384
5468 9284
1131 7215
7368 1074
2948 6764
7960 1676
3684 8758
459...

output:

11
11
11
11
11
11
12
11
11
12
11
11
11
11
12
11
11
12
11
11
11
11
11
12
11
11
12
11
11
11
11
11
11
11
11
11
11
11
11
11
11
12
11
11
12
12
11
12
11
12
11
11
11
11
11
11
11
11
11
11
11
11
11
12
11
11
11
11
12
11
11
11
11
11
11
12
11
11
12
11
11
11
11
12
12
11
12
11
11
11
11
11
11
11
11
11
12
12
11
11
...

result:

ok 100000 numbers