QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#400632#6621. Luggage LockSiilhouetteWA 89ms3880kbC++141.3kb2024-04-27 14:30:432024-04-27 14:30:44

Judging History

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

  • [2024-04-27 14:30:44]
  • 评测
  • 测评结果:WA
  • 用时:89ms
  • 内存:3880kb
  • [2024-04-27 14:30:43]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<set>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

char s1[10],s2[10];
int ans,a[10],b[10],c[10];

inline int sgn(int x)
{
	if(x>0)return 1;
	else if(x==0)return 0;
	else return -1;
}

inline void cal(int &res,int l,int r)
{
	if(l>r)return;
	int mini=1000000000;
	for(int i=l;i<=r;i++)
		mini=min(mini,a[i]);
	res+=mini;
	for(int i=l;i<=r;i++)
		a[i]-=mini;
	for(int i=l;i<=r;)
	{
		int j=i;
		if(!a[i]){ i++;continue; }
		while(j<r&&sgn(a[j+1])==sgn(a[i]))j++;
		cal(res,i,j);
		i=j+1;
	}
}

inline int sol()
{
	int res=0;
	for(int i=1;i<=4;)
	{
		if(!a[i]){ i++;continue; }
		int j=i;
		while(j<4&&sgn(a[j+1])==sgn(a[i]))j++;
		for(int k=i;k<=j;k++)
			a[k]=abs(a[k]);
		cal(res,i,j);
		i=j+1;
	}
	return res;
}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%s%s",s1+1,s2+1);
		for(int i=1;i<=4;i++)
			a[i]=s1[i]-'0',b[i]=s2[i]-'0',a[i]=b[i]-a[i];
		for(int i=1;i<=4;i++)
			c[i]=a[i];
		ans=1000000000;
		for(int i=0;i<16;i++)
		{
			for(int j=0;j<4;j++)
			{
				if(i>>j&1)a[j+1]=c[j+1];
				else a[j+1]=sgn(c[j+1])*(-1)*(10-abs(c[j+1]));
			}
			ans=min(ans,sol());
		}
		printf("%d\n",ans);
	}
	return 0;
}

詳細信息

Test #1:

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

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: 89ms
memory: 3804kb

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'