QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#646481 | #6621. Luggage Lock | wzxtsl# | WA | 2ms | 3924kb | C++23 | 1.1kb | 2024-10-16 23:41:19 | 2024-10-16 23:41:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
const int N=2007;
int n,m;
int s[10010];
int p[]={1,10,100,1000};
void solve(){
cin>>n>>m;
for(int i=0;i<4;i++){
int x=m/p[i]%10;
x-=n/p[i]%10;
x+=10;
x%=10;
m-=m/p[i]%10*p[i];
m+=x*p[i];
}
//cout<<m<<'\n';
cout<<s[m]<<'\n';
}
void init(){
queue<int> q;
q.push(0);
while(!q.empty()){
int now=q.front();
q.pop();
vector<int> v(10);
for(int i=0;i<4;i++)v[i]=now/p[i]%10;
for(int ii=1;ii!=-1;ii-=2)
for(int l=1;l<=4;l++){
for(int i=0;i<4;i++){
if(i+l>4)break;
vector<int> nw(10);
for(int j=0;j<4;j++)nw[j]=v[j];
for(int j=i;j<i+l;j++){
nw[j]+=1*ii;
nw[j]+=10;
nw[j]%=10;
}
int x=0;
for(int j=0;j<4;j++)x+=nw[j]*p[j];
if(!s[x]){
s[x]=s[now]+1;
q.push(x);
//if(s[x]<=3)cout<<x<<' '<<s[x]<<'\n';
}
}
}
}
}
signed main(){
fast;
init();
int t=1;
cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 3924kb
input:
6 1234 2345 1234 0123 1234 2267 1234 3401 1234 1344 1234 2468
output:
1 9 4 7 1 4
result:
wrong answer 2nd numbers differ - expected: '1', found: '9'