QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#204429#7560. Computer Networkucup-team133#WA 0ms3892kbC++202.4kb2023-10-07 11:26:572023-10-07 11:26:58

Judging History

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

  • [2023-10-07 11:26:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3892kb
  • [2023-10-07 11:26:57]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define all(x) (x).begin(), (x).end()
using ll = long long;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (int i = 0; i < int(v.size()); i++) os << v[i] << (i + 1 == int(v.size()) ? "" : " ");
    return os;
}

#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;
#else
#define debug(x) void(0)
#endif

constexpr int INF = (1 << 30) - 1;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int &x: a) cin >> x;
    for (int &x: b) cin >> x;

    vector<int> ord(n);
    iota(all(ord), 0);
    sort(all(ord), [&](int l, int r) { return a[l] < a[r]; });
    vector<int> na(n), nb(n);
    for (int i = 0; i < n; i++) {
        na[i] = a[ord[i]];
        nb[i] = b[ord[i]];
    }
    if (not is_sorted(all(b))) {
        cout << -1 << "\n";
        return 0;
    }

    vector<int> init(n - 1), to(n - 1);
    for (int i = 0; i + 1 < n; i++) {
        init[i] = a[i + 1] - a[i];
        to[i] = b[i + 1] - b[i];
        if (init[i] < to[i]) {
            cout << -1 << "\n";
            return 0;
        }
    }

    int ans = INF;
    map<pair<vector<int>, int>, int> mp;
    queue<pair<vector<int>, int>> que;
    que.emplace(init, a[0]);
    mp[{init, a[0]}] = 0;
    while (not que.empty()) {
        auto [v, f] = que.front();
        que.pop();
        int cur = mp[{v,f}];
        bool ok = true, same = true;
        for (int i = 0; i < n - 1; i++) {
            if (v[i] < to[i])ok = false;
            if (v[i] != to[i]) same = false;
        }
//        debug(v);
//        debug(f);
//        debug(cur);
        if (not ok) continue;
        if (same and f <= b[0]) {
            ans = min(ans, cur + (b[0] - f));
            continue;
        }
        for (int k = 0; k < 2; k++) {
            vector<int> u(n - 1);
            int x = f + k;
            for (int i = 0; i < n - 1; x += v[i++]) {
                u[i] = v[i] / 2;
                if ((v[i] & 1) and (x & 1)) u[i]++;
            }
            int nf = (f + k) / 2, ncur = cur + k + 1;
            if (not mp.count({u,nf})) que.emplace(u,nf);
            if (not mp.count({u,nf}) or ncur< mp[{u,nf}])
                mp[{u,nf}] = ncur;
        }
    }

    cout << (ans == INF ? -1 : ans) << "\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
1 2 3 4 5
6 6 6 6 7

output:

9

result:

ok 1 number(s): "9"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3824kb

input:

3
2 3 4
1 2 3

output:

-1

result:

ok 1 number(s): "-1"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

2
65536 65537
1 2

output:

32

result:

ok 1 number(s): "32"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

1
0
28

output:

28

result:

ok 1 number(s): "28"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3660kb

input:

1
249912
43

output:

26

result:

ok 1 number(s): "26"

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3656kb

input:

2
52522336 155670
52532336 165670

output:

-1

result:

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