QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#152449 | #6621. Luggage Lock | LFCode# | RE | 0ms | 0kb | C++14 | 1.3kb | 2023-08-28 09:03:30 | 2023-08-28 09:03:31 |
answer
#include<cstdio>
const int N=5;
int T[N],S[N],s[N],dd[N],d[10086],q[10086];
bool vis[10086];
int read(){
char ch=getchar();int nn=0,ssss=1;
while(ch<'0'||ch>'9'){if(ch=='-')ssss*=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){nn=nn*10+(ch-'0');ch=getchar();}
return nn*ssss;
}
int gd(){char ch=getchar();while(ch<'0'||ch>'9')ch=getchar();return ch-'0';}
bool solve(){
for(int i=1;i<=4;i++)S[i]=gd();
for(int i=1;i<=4;i++){
T[i]=gd();
dd[i]=T[i]-S[i];
if(dd[i]<0)dd[i]+=10;
}
int delta=dd[1]*1000+dd[2]*100+dd[3]*10+dd[4];
printf("%d\n",d[delta]);
}
bool bfs(){
vis[0]=true;int qh=1,qt=0;q[++qt]=0;
while(qh<=qt){
int np=q[qh++];int tmp=np;
for(int i=1;i<=4;i++){s[i]=np%10;np/=10;}
for(int l=1;l<=4;l++)
for(int r=l;r<=4;r++){
for(int k=l;k<=r;k++){
s[k]++;
if(s[k]==10)s[k]=0;
}
int rp=s[1]+s[2]*10+s[3]*100+s[4]*1000;
if(!vis[rp]){vis[rp]=true;d[rp]=d[tmp]+1;q[++qt]=rp;}
for(int k=l;k<=r;k++){
s[k]-=2;
if(s[k]<0)s[k]+=10;
}
rp=s[1]+s[2]*10+s[3]*100+s[4]*1000;
if(!vis[rp]){vis[rp]=true;d[rp]=d[tmp]+1;q[++qt]=rp;}
for(int k=l;k<=r;k++){
s[k]++;
if(s[k]==10)s[k]=0;
}
}
}
return true;
}
int main(){
bfs();
int T=read();
while(T--)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
6 1234 2345 1234 0123 1234 2267 1234 3401 1234 1344 1234 2468