QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#771781 | #6621. Luggage Lock | HaoHaovo | WA | 51ms | 4828kb | C++23 | 2.3kb | 2024-11-22 15:38:06 | 2024-11-22 15:38:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f3f3f3f3f
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
int dx[22] = {1111, 1110, 1100, 1000, 100, 110, 111, 10, 11, 1, -1111, -1110, -1100, -1000, -100, -110, -111, -10, -11, -1};
map<int, int> mp, mm;
int add(int x,int y)
{
string a = to_string(x),b = to_string(y);
int ans = 0;
while(a.size() < 4)
a = '0' + a;
while(b.size() < 4)
b = '0' + b;
// cout << a << " " << b << endl;
for(int i=0;i<4;i++)
{
ans = (ans * 10 + (a[i] + b[i] - 2*'0') % 10);
}
return ans;
}
int del(int x,int y)
{
string a = to_string(x),b = to_string(y);
int ans = 0;
while(a.size() < 4)
a = '0' + a;
while(b.size() < 4)
b = '0' + b;
if(a < b) swap(a,b);
for(int i=0;i<4;i++)
ans = (ans * 10 + (a[i] - b[i] + 10) % 10);
return ans;
}
void bfs()
{
queue<pair<int, int>> q;
q.push({0, 0});
mp[0] = 1;
mm[0] = 0;
while (!q.empty())
{
auto [x, y] = q.front();
q.pop();
// cout << x << " " << y << endl;
for (int i = 0; i < 10; i++)
{
int tp = add(x,dx[i]);
if (tp < 0)
tp = add(tp,9999);
if (mp[tp])
continue;
if (tp > 9999)
continue;
mp[tp] = 1;
mm[tp] = y + 1;
q.push({tp, y + 1});
}
for (int i = 0; i < 10; i++)
{
int tp = del(x,dx[i]);
if (tp < 0)
tp = add(tp,9999);
if (mp[tp])
continue;
if (tp > 9999)
continue;
mp[tp] = 1;
mm[tp] = y + 1;
q.push({tp, y + 1});
}
}
}
void solve()
{
int a, b;
cin >> a >> b;
// cout << add(0,1111) << endl;
// return ;
int ans = del(a,b);
// cout << ans << endl;
// int ans = abs(a - b);
cout << mm[ans] << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
bfs();
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 25ms
memory: 4824kb
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: 4828kb
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 7 6 9 10 7 8 7 11 11 6 8 5 4 8 5 9 7 9 4 10 8 8 6 8 5 7 6 7 5 7 7 6 8 4 10 6 5 8 7 8 7 9 7 8 7 5 9 7 6 7 11 10 10 7 5 6 5 7 8 9 9 7 7 6 10 8 5 7 9 10 7 10 5 12 7 6 7 8 6 8 8 7 8 7 8 11 7 6 5 5 6 6 5 9 5 9 6 7 7 7 11 9 9 8 5 11 10 7 3 5 6 7 11 8 8 6 7 12 5 5 6 11 8 6 11 6 10 7 6 11 5 9 7 7 5 10 7 5...
result:
wrong answer 2nd numbers differ - expected: '6', found: '7'