QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#675229 | #6621. Luggage Lock | end | WA | 350ms | 3708kb | C++14 | 1.2kb | 2024-10-25 18:10:13 | 2024-10-25 18:10:15 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int T;
char A[6], B[6];
int a[6], b[6];
int aa[6], bb[6];
int ans;
void dfs(int u,int t)
{
if (u == 4)
{
ans = min(ans, t);
return;
}
if (a[u] == b[u])
{
dfs(u + 1, t);
return;
}
for (int i = u; i < 4; i++)
{
int j = i - u + 1;
int sub1, sub2;
if (a[u] < b[u])
{
sub1 = b[u] - a[u];
sub2 = 10 - (b[u] - a[u]);
}
else
{
sub1 = 10 - (a[u] - b[u]);
sub2 = a[u] - b[u];
}
for (int k = u; k <= u + j - 1; k++)
{
a[k] = (a[k] + sub1) % 10;
}
dfs(u + 1, t + sub1);
for (int k = u; k <= u + j - 1; k++)
{
a[k] = (a[k] - sub1 + 10) % 10;
}
for (int k = u; k <= u + j - 1; k++)
{
a[k] = (a[k] - sub2 + 10) % 10;
}
dfs(u + 1, t + sub2);
for (int k = u; k <= u + j - 1; k++)
{
a[k] = (a[k] + sub2) % 10;
}
}
}
void solve()
{
ans = 2e9;
cin >> A >> B;
for (int i = 0; i < 4; i++)
{
a[i] = A[i] - '0';
b[i] = B[i] - '0';
}
dfs(0, 0);
cout << ans << endl;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> T;
while (T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
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: 350ms
memory: 3708kb
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 8 6 10 10 7 8 8 11 9 7 8 5 5 8 5 9 8 9 4 8 8 9 6 8 6 8 6 9 5 7 7 6 8 4 10 6 5 6 7 8 7 5 8 8 8 5 9 7 6 8 11 10 10 7 5 6 5 7 8 8 9 5 7 6 6 8 5 7 9 10 7 11 6 6 7 8 7 8 7 8 8 8 8 7 9 7 7 6 6 5 6 6 5 7 5 9 6 7 8 7 9 6 9 5 5 8 10 7 3 5 8 8 9 8 8 6 7 10 5 5 6 9 8 6 8 7 6 9 6 11 5 10 7 7 5 10 7 5 8 9 8 7 ...
result:
wrong answer 2nd numbers differ - expected: '6', found: '8'