QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#704079 | #6621. Luggage Lock | Yurily# | WA | 20ms | 3904kb | C++20 | 1.2kb | 2024-11-02 19:14:13 | 2024-11-02 19:14:13 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N = 4;
char a[N + 3], b[N + 3];
int c[N + 3], t[N + 3];
int ans;
void dfs(int step, int sum){
if(step > N){
ans = min(ans, sum);
return ;
}
if(sum > ans)
return ;
//1: 0->c[i]
t[step] = 1;
if(t[step - 1] == 1)
if(c[step] > c[step - 1])
dfs(step + 1, sum + c[step] - c[step - 1]);
else
dfs(step + 1, sum);
else
dfs(step + 1, sum + c[step]);
//2: n-c[i]<-0
t[step] = 2;
if(t[step - 1] == 2)
if(c[step] < c[step - 1])
dfs(step + 1, sum + c[step - 1] - c[step]);
else
dfs(step + 1, sum);
else
dfs(step + 1, sum + 10 - c[step]);
}
void sol(){
scanf("%c%c%c%c %c%c%c%c\n", &a[1], &a[2], &a[3], &a[4], &b[1], &b[2], &b[3], &b[4]);
for(int i = 1; i <= N; i++)
c[i] = (b[i] - a[i] + 10) % 10;
ans = 20;
t[0] = -1;
dfs(1, 0);
printf("%d\n", ans);
}
int main(){
int T;
scanf("%d\n", &T);
while(T--)
sol();
return 0;
}
詳細信息
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: 20ms
memory: 3904kb
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'