QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#242784#6621. Luggage LockRonbogo#WA 102ms3748kbC++202.8kb2023-11-07 17:11:002023-11-07 17:11:00

Judging History

你现在查看的是最新测评结果

  • [2023-11-07 17:11:00]
  • 评测
  • 测评结果:WA
  • 用时:102ms
  • 内存:3748kb
  • [2023-11-07 17:11:00]
  • 提交

answer

#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
FILE *__ = freopen("in.txt", "r", stdin);
#endif
using namespace std;
#define LL long long

const int maxn = 4e3 + 5, mod = 998244353;

int a[10], b[10], c[10], d[10], e[10];
string s;

int f1(int x) { return abs(a[x]); }

int f2(int l, int r) { return max(f1(l), f1(r)); }

int f3(int l, int r) {
    if ((a[l] <= a[l + 1] && a[l + 1] <= a[r]) ||
        (a[l] >= a[l + 1] && a[l + 1] >= a[r]))
        return f2(l, r);
    if ((a[l] <= 0 && a[l] >= a[l + 1] && a[r] >= a[l + 1]) ||
        (a[l] >= 0 && a[l] <= a[l + 1] && a[r] >= a[l + 1]))
        return f1(l + 1);
    // if ((a[l] >= 0 && a[l] >= a[l + 1] && a[r] >= a[l + 1]) ||
    //     (a[l] <= 0 && a[l] <= a[l + 1] && a[r] >= a[l + 1]))
    return abs(a[l + 1]) + abs(a[l] - a[l + 1]) + abs(a[r] - a[l + 1]);
}

int f4() {
    if ((a[1] <= a[2] && a[2] <= a[3] && a[3] <= a[4]) ||
        (a[1] >= a[2] && a[2] >= a[3] && a[3] >= a[4]))
        return f2(1, 4);
    if (a[1] < 0)
        for (int j = 1; j <= 4; ++j) a[j] = -a[j];
    int mi = 100;
    for (int j = 1; j <= 4; ++j) mi = min(mi, a[j]);
    for (int j = 1; j <= 4; ++j) a[j] -= mi;
    if (a[1] == 0) return f3(2, 4) + mi;
    if (a[4] == 0) return f3(1, 3) + mi;
    if (a[2] == 0) return f2(3, 4) + a[1] + mi;
    return f2(1, 2) + a[4] + mi;
}

int f() {
    return (a[1] >= 0) * 8 + (a[2] >= 0) * 4 + (a[3] >= 0) * 2 +
           (a[4] >= 0) * 1;
}

void sol() {
    string s1, s2;
    cin >> s1 >> s2;
    int ans = 100;
    for (int i = 0; i < 4; ++i) d[i + 1] = s1[i] - '0', e[i + 1] = s2[i] - '0';
    for (int i = 0; i < 81; ++i) {
        for (int j = 1; j <= 4; ++j) b[j] = d[j], c[j] = e[j];
        int tmp = 1;
        for (int j = 1; j <= 4; ++j) {
            if (a[j] / tmp % 3 == 1) b[j] += 10;
            if (a[j] / tmp % 3 == 2) b[j] -= 10;
            tmp *= 3;
        }
        for (int j = 1; j <= 4; ++j) a[j] = c[j] - b[j];
        int x = f();
        if (x == 8 || x == 7) ans = min(ans, f2(2, 4) + f1(1));
        if (x == 14 || x == 1) ans = min(ans, f2(1, 3) + f1(4));
        if (x == 15 || x == 0) ans = min(ans, f4());
        if (x == 12 || x == 3) ans = min(ans, f2(1, 2) + f2(3, 4));
        if (x == 9 || x == 6) ans = min(ans, f1(1) + f1(4) + f2(2, 3));
        if (x == 10 || x == 5) ans = min(ans, f1(1) + f1(2) + f1(3) + f1(4));
        if (x == 2 || x == 13) ans = min(ans, f1(3) + f1(4) + f2(1, 2));
        if (x == 4 || x == 11) ans = min(ans, f1(1) + f1(2) + f2(3, 4));
        // cout << i << ' ' << ans << '\n';
        // if (i == 1) {
        //     cout << a[1] << ' ' << a[2] << ' ' << a[3] << ' ' << a[4] << '\n';
        // }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int _ = 1;
    cin >> _;
    while (_--) sol();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3520kb

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: 102ms
memory: 3748kb

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:

9
6
12
11
6
7
7
13
14
11
8
13
5
4
5
9
8
12
10
4
10
8
18
18
22
12
8
6
4
7
16
10
12
24
2
11
6
5
10
13
13
9
9
14
4
10
5
9
7
6
8
11
11
6
7
5
12
5
16
16
12
6
15
9
6
20
8
6
13
8
20
7
12
21
22
7
14
6
10
12
8
8
13
13
10
11
15
6
12
5
10
15
6
5
13
12
8
7
5
13
9
11
14
6
10
5
13
17
14
11
5
13
11
12
9
14
2
6
8
1...

result:

wrong answer 1st numbers differ - expected: '3', found: '9'