QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#733504#6621. Luggage Lock1ockhartWA 51ms3780kbC++201.2kb2024-11-10 19:29:442024-11-10 19:29:44

Judging History

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

  • [2024-11-10 19:29:44]
  • 评测
  • 测评结果:WA
  • 用时:51ms
  • 内存:3780kb
  • [2024-11-10 19:29:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"

const int N = 1e5 + 10, inf = 1e18;

vector<int> a(9), b(9);
int ans = inf;
void dfs(int cur, int sum, int res) {
	
	if (cur == 5) {
		ans = min(ans, res);
		return;
	}
	int st = a[cur], ed = (a[cur] + sum + 10 ) % 10, cnt;
	if (sum >= 0) {
		cnt = (b[cur] - st + 10) % 10;
	} else {
		cnt = (st - b[cur] + 10) % 10;
	}
	if (cnt <= abs(sum)) {
		dfs(cur + 1, sum > 0 ? cnt : -cnt, res);
		dfs(cur + 1, 0, res);
	} else {
		int dis1 = (b[cur] - ed + 10) % 10, dis2 = (ed - b[cur] + 10) % 10;
		dfs(cur + 1, sum + dis1, res + dis1);
		dfs(cur + 1, sum - dis2, res + dis2); //继承上轮

		dis1 = (b[cur] - st + 10) % 10, dis2 = (st - b[cur] + 10) % 10;
		dfs(cur + 1, dis1, res + dis1);
		dfs(cur + 1, -dis2, res + dis2); //不继承
	}

}
void solve() {
	string s1, s2;
	cin >> s1 >> s2;
	for (int i = 1; i <= 4; i++) {
		a[i] = a[i + 4] = s1[i - 1] - '0';
		b[i] = b[i + 4] = s2[i - 1] - '0';
	}
	ans = inf;
	dfs(1, 0, 0);
	cout << ans << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int q = 1;
	cin >> q;
	while (q--) {
		solve();
	}
}

詳細信息

Test #1:

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

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: 51ms
memory: 3780kb

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'