QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692052#6621. Luggage LockMENDAX#WA 37ms3564kbC++201.4kb2024-10-31 13:42:042024-10-31 13:42:06

Judging History

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

  • [2024-10-31 13:42:06]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:3564kb
  • [2024-10-31 13:42:04]
  • 提交

answer

#include <bits/stdc++.h>

#define int long long
#define endl '\n'

using namespace std;
const int N = 1e4 + 10,INF=1e9+10;

int a[N],b[N];
int ans=INF;

int su(int au,int bu){
	return bu-au<0?bu-au+10:bu-au;
}

int sd(int au,int bu){//向下走的步数 
	return au-bu<0?au-bu+10:au-bu;
}

void dfs(int u,int up,int down,int sum){//上一个up和下一个down的 
	if(sum>=ans) return ;
	if(u==5){
		ans=min(ans,sum);
		return ;
	}
	
	int mu=INF,md=INF;
	int tu=0;
	for(int i=0;i<=up;i++){//枚举向上走的步数 
		int au=(a[u]+i)%10;
		if(mu>=su(au,b[u])){
			mu=su(au,b[u]);
			tu=i;//向上走这么多步后再向上走mu步 
		}
		md=min(md,sd(au,b[u])); 
	} 
	dfs(u+1,mu+tu,0,sum+mu);
	dfs(u+1,0,md,sum+md);
	mu=INF,md=INF;
	int td=0;
	for(int i=0;i<=down;i++){//枚举向上走的步数 
		int au=(a[u]-i);
		if(au<0) au+=10;
		mu=min(mu,su(au,b[u]));
		if(md>=sd(au,b[u])){
			md=sd(au,b[u]);
			td=i;
		}
	} 
	dfs(u+1,mu,0,sum+mu);
	dfs(u+1,0,md+td,sum+md);
}

void solve() {
	ans=INF;
	string s,t;cin >> s >> t;
	s='.'+s;t='.'+t;
	for(int i=1;i<=4;i++){
		a[i]=s[i]-'0';
		b[i]=t[i]-'0';
	}
	dfs(2,su(a[1],b[1]),0,su(a[1],b[1]));
	dfs(2,0,sd(a[1],b[1]),sd(a[1],b[1]));
	cout<<ans<<endl; 
}
/*
6
1234 2345
1234 0123
1234 2267
1234 3401
1234 1344
1234 2468
*/
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T;cin >> T;
	while (T--) solve();
}

詳細信息

Test #1:

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

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: 37ms
memory: 3564kb

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'