QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#447431#8805. Pizza Partyarbuzick#0 1257ms77436kbC++201.9kb2024-06-18 14:29:012024-06-18 14:29:01

Judging History

This is the latest submission verdict.

  • [2024-06-18 14:29:01]
  • Judged
  • Verdict: 0
  • Time: 1257ms
  • Memory: 77436kb
  • [2024-06-18 14:29:01]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

constexpr int maxn = 1e6 + 5;

vector<int> g[maxn];

int used[maxn];

int t = 0;

int mt[maxn];

bool dfs(int v) {
    if (used[v] == t) {
        return false;
    }
    used[v] = t;
    for (auto u : g[v]) {
        if (mt[u] == -1 || dfs(mt[u])) {
            mt[u] = v;
            return true;
        }
    }
    return false;
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        b[i]--;
    }
    vector<int> aa = a, bb = b;
    sort(aa.begin(), aa.end());
    sort(bb.begin(), bb.end());
    if (aa != bb) {
        cout << -1 << '\n';
        return;
    }
    reverse(b.begin(), b.end());
    vector<int> pos(n), pos2(n);
    for (int i = 0; i < n; ++i) {
        pos[b[i]] = i;
        pos2[a[i]] = i;
    }
    set<int> s;
    int cnt = 0;
    vector<int> ans(n);
    for (int i = 0; i < n; ++i) {
        auto it = s.lower_bound(pos[a[i]]);
        if (it != s.begin()) {
            it--;
            if (*it > pos[a[i]]) {
                ans[i] = ans[pos2[b[*it]]];
                s.erase(it);
                s.insert(pos[a[i]]);
            } else {
                ans[i] = cnt++;
                s.insert(pos[a[i]]);
            }
        } else {
            ans[i] = cnt++;
            s.insert(pos[a[i]]);
        }
    }
    cout << s.size() << endl;
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << " \n"[i == n - 1];
    }
    reverse(b.begin(), b.end());
    for (int i = 0; i < n; ++i) {
        cout << ans[pos2[b[i]]] << " \n"[i == n - 1];
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 244ms
memory: 30296kb

input:

1000000
1 1 1 2 1 1 1 1 1 2 1 1 1 2 1 2 1 1 1 2 2 1 2 1 2 2 2 2 2 1 2 2 1 1 1 2 1 1 2 1 2 2 2 2 2 2 2 1 2 1 2 2 1 1 2 1 2 2 2 1 1 2 2 1 1 1 1 2 1 2 2 1 2 2 2 1 2 1 1 2 1 1 1 2 1 2 2 1 1 1 2 2 2 2 1 2 1 1 1 2 2 2 1 1 1 1 1 2 2 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 2 1 1 2 1 ...

output:

2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 ...

result:

wrong answer Integer element c_i[1] equals to 0, violates the range [1, 2]

Subtask #2:

score: 0
Wrong Answer

Test #24:

score: 0
Wrong Answer
time: 6ms
memory: 4172kb

input:

5000
3140 3541 3540 3884 2792 3966 1359 549 2273 2669 2100 4448 4722 3937 23 3964 4910 3490 61 2723 2554 4177 3025 4909 2127 939 2536 835 2801 459 3374 972 4687 2102 2919 4367 4905 3414 869 2272 507 4210 2906 2584 1639 2020 3287 3447 2500 4866 3284 2010 1826 331 1873 3895 4946 889 3059 894 4233 2541...

output:

5000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

result:

wrong answer Integer element c_i[1] equals to 0, violates the range [1, 5000]

Subtask #3:

score: 0
Wrong Answer

Test #39:

score: 0
Wrong Answer
time: 1257ms
memory: 77436kb

input:

1000000
134990 280863 995875 82485 490673 517020 49269 636214 69331 626226 96180 743288 524606 324456 937362 164072 680663 931183 195920 618400 741187 164410 478750 590824 160168 192530 154228 661164 17160 343556 653139 229351 350929 719054 634472 433811 352199 163260 833268 56711 963125 346135 9350...

output:

1000000
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 10...

result:

wrong answer Integer element c_i[1] equals to 0, violates the range [1, 1000000]