QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#648851 | #6621. Luggage Lock | yeah14 | WA | 44ms | 3840kb | C++17 | 2.3kb | 2024-10-17 20:41:18 | 2024-10-17 20:41:19 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ull long long
#define PII pair<int ,int>
const int INF = -1145141919810;
const int mod = 1e9 + 7;
const int N = 1e6 + 7;
int fp(int a, int x, int mod) {
int ans = 1;
while (x) {
if (x & 1)ans *= a;
ans %= mod;
a *= a;
a %= mod;
x >>= 1;
}
return ans;
}
map<char, map<char,int>>p;
//map<char, int>p;
void solve() {
int a[4],b[4];
int c[4],d[4];
string s1, s2;
cin >> s1 >> s2;
for (int i = 0; i < 4; i++) {
a[i] = s1[i] - '0';
b[i] = s2[i] - '0';
c[i] = b[i] - a[i];
d[i] = c[i];
}
int ans = 0x3f3f3f;
for (int k = 0; k < 16; k++) {
int cc[4];
int j = k;
int f = 8;
int sss = 0;
for (int i = 0; i < 4; i++) {
cc[i] = j % 2;
j /= 2;
}
for (int i = 0; i < 4; i++) {
if (cc[i] == 1) {
if (c[i] > 0)d[i] =c[i]- 10;
else if (c[i] < 0)d[i] =c[i]+ 10;
}
else d[i] = c[i];
}
int s = 0, e = 0;
int t = abs(d[0]);
int res = 0;
for (int i = 0; i < 4; i++) {
if (i == 3) {
if (e != 3)res += abs(d[i]);
else {
res += t;
for (int i = s; i < e; i++) {
res += abs(d[i]) - t;
}
s = e;
t = 0;
}
}
else if (d[i] * d[i + 1] > 0)
{
e = i + 1;
t = min(t, abs(d[i + 1]));
}
else {
if (e < s) {
res += abs(d[i]);
s = i + 1;
continue;
}
res += t;
for (int i = s; i < e; i++) {
res += abs(d[i])-t;
}
s = e+1;
t = 0x3f3f;
}
}
ans = min(ans, res);
/*cout << res << endl;
for (int i = 0; i < 4; i++) {
cout << d[i] << " ";
}
cout << endl;*/
}
cout << ans << endl;
}
//&&(((sum[n]+k)%mid==0)||(sum[n]/mid!=(sum[n]+k)/mid)||(mid-(sum[n]%mid)>=k))
signed main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
//er(9e7);
//cout << 7*4% 10;
while (t--)solve();
//pr[5216953]
}
//int n;
//cin >> n;
//for (int i = 1; i <= n; i++) {
// cin >> a[i];
//}
//int maxx = 0, minn = INF;
//int sum = 0;
//for (int i = n; i <= 1; i++) {
// sum += minn;
// if (top == 0) {
// minn = a[i];
// st[top++] = a[i];
// }
// else {
// if (a[i] > top && a[i] > minn)
// }
//}
//cout << maxx - minn << endl;
//7 2 1 4 5 1 3 3
//4 1000 1000 1000 1000
//0
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3568kb
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: 44ms
memory: 3840kb
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:
1 5 6 6 8 3 6 6 6 6 6 4 5 3 5 3 7 5 5 3 4 6 6 4 6 1 5 5 5 1 4 7 6 7 4 6 5 3 8 5 5 6 5 7 6 6 2 5 4 2 5 8 6 8 6 2 5 7 3 7 7 6 2 6 5 6 8 1 7 3 6 6 8 5 3 5 6 5 3 7 4 5 7 6 2 5 6 4 6 4 6 4 5 4 7 4 4 2 6 6 7 8 3 8 4 2 4 8 3 3 5 6 6 5 4 8 2 5 8 7 3 4 5 4 5 4 6 5 7 5 7 5 4 7 3 3 8 7 4 3 8 4 3 7 7 9 2 6 7 3 ...
result:
wrong answer 1st numbers differ - expected: '3', found: '1'