QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#582349#6621. Luggage LockSoestxWA 0ms3924kbC++141.7kb2024-09-22 16:07:252024-09-22 16:07:26

Judging History

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

  • [2024-09-22 16:07:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3924kb
  • [2024-09-22 16:07:25]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fi first
#define se second
#define lowbit(x) x&(-x)
#define pll pair<int,int>
typedef long long ll;
//typedef unsigned long long ull;
const int N=1e6+10,M=1e6,mod=998244353;
int n,m,k;
int num[N];
int res;

map<pll,int> dp,dap;
//int dp[10010][10010],dap[10010][10010];
int pw[5];
int dfs(int x,int y,int w);
int get(int x,int y,int w)
{
	if(x==y) return 0;
	if(w==1)
	{
		int t=abs(x-y);
		if(t>10-t) t=10-t;
		return t;
	}
	if(dap[{x,y}]) return dap[{x,y}];
	
	int x1=0,y1=0;
	int xx=x,yy=y;
	int ans=36;
	for(int i=w-1;i;i--)
	{
		x1=x1*10+x/pw[i];
		x%=pw[i];
		
		y1=y1*10+y/pw[i];
		y%=pw[i];
		int tmp=dfs(x1,y1,w-i)+dfs(x,y,i);
		cout<<i<<"-- "<<x1<<" "<<x<<" "<<y1<<" "<<y<<" "<<tmp<<endl;
		if(ans>tmp) ans=tmp;
	}
//	cout<<xx<<" "<<yy<<" "<<ans<<endl;
	return dap[{xx,yy}]=ans;
}

int dfs(int x,int y,int w)
{
	if(x==y) return 0;
	if(w==1)
	{
		int t=abs(x-y);
		if(t>10-t) t=10-t;
		return t;
	}
	if(dp[{x,y}]) return dp[{x,y}];
	
	int ans=36;
	int p=x;
	int tmp[10];
	for(int i=1;i<=w;i++) tmp[i]=p%10,p/=10;
	
	for(int i=-9;i<=9;i++)
	{
		int x1=0;
		for(int j=w;j>=1;j--)
		{
			int t=(tmp[j]+i+10)%10;
			x1=x1*10+t;
		}
		//cout<<x<<" "<<i<<" "<<x1<<"-------"<<endl;
		int tmp=abs(i)+get(x1,y,w);
		if(ans>tmp) ans=tmp;
	}
	
	return dp[{x,y}]=ans;
}

void solve()
{
	int x,y;
	scanf("%d %d",&x,&y);
	printf("%d\n",dfs(x,y,4));
}

signed main()
{
	pw[0]=1;
	for(int i=1;i<=4;i++) pw[i]=pw[i-1]*10;
	//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int T;
	T=1;
	cin>>T;
	while(T--) solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3924kb

input:

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

output:

1-- 7 8 4 5 6
1-- 8 9 4 5 8
1-- 9 0 4 5 10
1-- 0 1 4 5 8
1-- 1 2 4 5 6
1-- 2 3 4 5 4
1-- 3 4 4 5 2
1-- 5 6 4 5 2
1-- 6 7 4 5 4
2-- 5 67 3 45 4
1-- 6 7 3 4 6
1-- 7 8 3 4 8
1-- 8 9 3 4 10
1-- 9 0 3 4 8
1-- 0 1 3 4 6
1-- 1 2 3 4 4
1-- 2 3 3 4 2
1-- 4 5 3 4 2
1-- 5 6 3 4 4
1-- 56 7 34 5 4
2-- 6 78 3 45 ...

result:

wrong output format Expected integer, but "1--" found