QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#245167#6621. Luggage LockFL_WA 177ms3816kbC++142.5kb2023-11-09 19:33:582023-11-09 19:34:00

Judging History

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

  • [2023-11-09 19:34:00]
  • 评测
  • 测评结果:WA
  • 用时:177ms
  • 内存:3816kb
  • [2023-11-09 19:33:58]
  • 提交

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] < 0)
        for (int i = l; i <= r; ++i) a[i] = -a[i];
    int mi = 100;
    for (int i = l; i <= r; ++i) mi = min(a[i], mi);
    for (int i = l; i <= r; ++i) a[i] -= mi;
    if (a[l + 1] == 0) return mi + f1(l) + f1(r);
    if (a[l] == 0) return mi + f2(l + 1, r);
    return mi + f2(l, l + 1);
}

int f4() {
    if (a[1] < 0)
        for (int i = 1; i <= 4; ++i) a[i] = -a[i];
    vector<int> v;
    for (int i = 1; i <= 4; ++i) v.push_back(a[i]);
    sort(v.begin(), v.end());
    if (a[1] == v[0]) return f3(2, 4);
    if (a[4] == v[0]) return f3(1, 3);
    int res = 0;
    for (int i = 1; i <= 4; ++i) a[i] -= v[1];
    if (a[2] < 0) res = f2(3, 4) + f1(1);
    if (a[3] < 0) res = f2(1, 2) + f1(4);
    if (a[1] == 0) res = f3(2, 4);
    if (a[4] == 0) res = f3(1, 3);
    if (a[2] == 0 && a[3] == 0) res = f1(1) + f1(4);
    return res + v[1];
}

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 (i / tmp % 3 == 1) b[j] += 10;
            if (i / tmp % 3 == 2) b[j] -= 10;
            tmp *= 3;
        }
        for (int j = 1; j <= 4; ++j) a[j] = c[j] - b[j];
        int x = f(), anss = 100;
        if (x == 8 || x == 7) anss = f3(2, 4) + f1(1);
        if (x == 14 || x == 1) anss = f3(1, 3) + f1(4);
        if (x == 15 || x == 0) anss = f4();
        if (x == 12 || x == 3) anss = f2(1, 2) + f2(3, 4);
        if (x == 9 || x == 6) anss = f1(1) + f1(4) + f2(2, 3);
        if (x == 10 || x == 5) anss = f1(1) + f1(2) + f1(3) + f1(4);
        if (x == 2 || x == 13) anss = f1(3) + f1(4) + f2(1, 2);
        if (x == 4 || x == 11) anss = f1(1) + f1(2) + f2(3, 4);
        ans = min(ans, anss);
    }
    cout << ans << '\n';
}

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

詳細信息

Test #1:

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

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: 177ms
memory: 3816kb

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
6
9
7
5
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
5
7
9
5
5
6
6
8
5
7
8
10
6
10
5
5
7
5
6
8
6
8
7
6
8
7
8
5
7
6
5
5
6
6
5
7
5
9
6
7
6
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
7
6
3
7
6
11
5
9
6
7
5
10
7
5
8
9
8
7
7
6...

result:

wrong answer 4th numbers differ - expected: '8', found: '6'