QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693078 | #6621. Luggage Lock | MENDAX# | WA | 24ms | 3848kb | C++20 | 1.5kb | 2024-10-31 15:30:01 | 2024-10-31 15:30:02 |
Judging History
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 dp[5][10][2];//µ±Ç°ÄÜÁ¬ÐøµÄºÍ²»ÄÜÁ¬ÐøµÄ
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 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';
}
memset(dp,0x3f,sizeof dp);
dp[1][su(a[1],b[1])][0]=su(a[1],b[1]);//0±íʾÏòÉÏ
dp[1][sd(a[1],b[1])][1]=sd(a[1],b[1]);
for(int i=2;i<=4;i++){
int p1=0x3f,p2=0x3f;
for(int j=0;j<=9;j++){//ö¾ÙÉÏÒ»¸öÏòÉÏ»òÕß˵ÏòϵIJ½Êý
int au=(a[i]+j)%10,ad=(a[i]-j+10)%10;
p1=min(dp[i-1][j][0],p1),p2=min((dp[i-1][j][1]),p2);
dp[i][su(a[i],b[i])][0]=min(dp[i][su(a[i],b[i])][0],dp[i-1][j][0]+(j>=su(a[i],b[i])?0:su(au,b[i])));
dp[i][sd(a[i],b[i])][1]=min(dp[i][sd(a[i],b[i])][1],dp[i-1][j][1]+(j>=sd(a[i],b[i])?0:sd(ad,b[i])));
}
dp[i][su(a[i],b[i])][0]=min(dp[i][su(a[i],b[i])][0],p2+su(a[i],b[i]));
dp[i][sd(a[i],b[i])][1]=min(dp[i][sd(a[i],b[i])][1],p1+sd(a[i],b[i]));
}
for(int j=0;j<=9;j++) ans=min(ans,min(dp[4][j][0],dp[4][j][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();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
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: 24ms
memory: 3620kb
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'