QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#233205 | #6621. Luggage Lock | icreiys | WA | 0ms | 3600kb | C++20 | 1.5kb | 2023-10-31 15:07:57 | 2023-10-31 15:07:58 |
Judging History
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)x+=10;
if(x<0||x>=10){
while(1){
ans=ans+1;
ans=ans-1;
}
}
if(x == 0){
dfs(pos+1,0,cnt);
}
else{
//逆时针转
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);
}
}
}
}
void solve()
{
string s1,s2;
cin>>s1>>s2;
cout<<"*"<<s1<<" "<<s2<<endl;
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: 0
Wrong Answer
time: 0ms
memory: 3600kb
input:
6 1234 2345 1234 0123 1234 2267 1234 3401 1234 1344 1234 2468
output:
*1234 2345 1 *1234 0123 1 *1234 2267 4 *1234 3401 5 *1234 1344 1 *1234 2468 4
result:
wrong output format Expected integer, but "*1234" found