QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227363#6621. Luggage Lockwhsyhyyh#RE 0ms0kbC++14945b2023-10-27 13:22:012023-10-27 13:22:02

Judging History

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

  • [2023-10-27 13:22:02]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-10-27 13:22:01]
  • 提交

answer

#include<bits/stdc++.h>
#define N 200010
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int T,a[5],b[5];
int dis[10010];
char s[5],t[5];
void bfs() {
	memset(dis,63,sizeof(dis));
	dis[0]=0;
	queue<int>qu;qu.push(0);
	int x,y;
	while(!qu.empty()) {
		x=qu.front(),qu.pop();
		int tmp=x;
		drep(i,4,1) {
			a[i]=tmp%10,tmp/=10;
		}
		rep(k,-1,1) if(k) rep(i,1,4) rep(j,1,4) {
			y=0;
			rep(l,1,4) {
				b[l]=a[l];
				if(l>=i&&l<=j) b[l]+=k;
				if(b[l]<0) b[l]+=10;
				y=(y<<1)+(y<<3)+b[l];
			}
			if(dis[y]>dis[x]+1) dis[y]=dis[x]+1,qu.push(y);
		}
	}
}
int main(){
	bfs();
    scanf("%d",&T);
    while(T--) {
        scanf("%s%s",s+1,t+1);
        int res=0;
        rep(i,1,4) {
            a[i]=t[i]-s[i];
            if(a[i]<0) a[i]+=10;
			res=(res<<1)+(res<<3)+(a[i]);
        }
        printf("%d\n",dis[res]);
    }
    return 0;
}

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

output:


result: