QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#233158#6621. Luggage Lockextreme1228#WA 17ms3832kbC++202.2kb2023-10-31 14:20:332023-10-31 14:20:34

Judging History

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

  • [2023-10-31 14:20:34]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:3832kb
  • [2023-10-31 14:20:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int ans;
int a[10];


void dfs(int pos,int val,int cnt)
{
    if(pos == 5){
        ans = min(ans,cnt);
        return;
    }
    int x = a[pos];
    if(x == 0){
        dfs(pos+1,0,cnt);
    }
    else if(x>0){
        //逆时针转
        int tmp_x = -x;
        if(val<=tmp_x){
            dfs(pos+1,tmp_x,cnt);
        }
        else{
            if(val<0){
                int tmp = val - tmp_x;
                dfs(pos+1,tmp_x,cnt+tmp);
            }
            else{
                int tmp = x;
                dfs(pos+1,tmp_x,cnt+tmp);
            }
        }
        //顺时针转
        tmp_x = 10 - x;
        if(val >= tmp_x){
            dfs(pos+1,tmp_x,cnt);
        }
        else{
            if(val>0){
                int tmp = tmp_x - val;
                dfs(pos+1,tmp_x,cnt+tmp);
            }
            else{
                int tmp = tmp_x;
                dfs(pos+1,tmp_x,cnt+tmp);
            }
        }
    }
    else{
        //逆时针转
        int tmp_x = -10 - x;
        if(val<=tmp_x){
            dfs(pos+1,tmp_x,cnt);
        }
        else{
            if(val<0){
                int tmp = val - tmp_x;
                dfs(pos+1,tmp_x,cnt+tmp);
            }
            else{
                int tmp = abs(tmp_x);
                dfs(pos+1,tmp_x,cnt+tmp);
            }
        }

        //顺时针
        tmp_x = abs(x);
        if(val>=tmp_x){
            dfs(pos+1,tmp_x,cnt);
        }
        else{
            if(val>0){
                int tmp = tmp_x - val;
                dfs(pos+1,tmp_x,cnt+tmp);
            }
            else{
                int tmp = tmp_x;
                dfs(pos+1,tmp_x,cnt+tmp);
            }
        }
    }
}
void solve()
{
    string s1,s2;
    cin>>s1>>s2;
    for(int i=1;i<=4;i++){
        a[i] = s2[i-1] - s1[i-1];
    }
    ans = 100;
    dfs(1,0,0);
    cout<<ans<<"\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t  = 1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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: -100
Wrong Answer
time: 17ms
memory: 3500kb

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
11
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:

wrong answer 73rd numbers differ - expected: '10', found: '11'