Submission #1055898

# Submission time Handle Problem Language Result Execution time Memory
1055898 2024-08-13T06:21:52 Z 4321(#11112) Pizza Party (CCO24_day1problem2) C++17
12 / 12
646 ms 136924 KB
#include<bits/stdc++.h>
using namespace std;

#define fast ios::sync_with_stdio(false); cin.tie(NULL);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define mp make_pair

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n;
vector<int> g[1000010];
int a[1000010];
int b[1000010];

int main() {
    fast;

    cin >> n;
    for(int i=1; i<=n; i++) {
        int x;
        cin >> x;
        g[x].eb(i);
    }

    set<pii> S;
    for(int i=1; i<=n; i++) {
        int x;
        cin >> x;
        if(g[x].empty()) {
            cout << -1;
            return 0;
        }

        int y = g[x].back();
        g[x].pop_back();

        auto it = S.lower_bound(mp(y, 0));
        int c = S.size()+1;
        if(it != S.end()) {
            c = it->se;
            S.erase(it);
        }
        a[y] = b[i] = c;
        S.insert(mp(y, c));
    }

    cout << S.size() << "\n";
    cout << a[1];
    for(int i=2; i<=n; i++) cout << " " << a[i];
    cout << "\n";
    cout << b[1];
    for(int i=2; i<=n; i++) cout << " " << b[i];
}
# Verdict Execution time Memory Grader output
1 Correct 163 ms 39856 KB good job!
2 Correct 163 ms 43692 KB good job!
3 Correct 171 ms 43552 KB good job!
4 Correct 170 ms 43712 KB good job!
5 Correct 207 ms 43544 KB good job!
6 Correct 170 ms 43848 KB good job!
7 Correct 163 ms 43688 KB good job!
8 Correct 163 ms 39968 KB good job!
9 Correct 187 ms 40100 KB good job!
10 Correct 168 ms 39856 KB good job!
11 Correct 163 ms 39856 KB good job!
12 Correct 164 ms 39708 KB good job!
13 Correct 10 ms 23900 KB good job!
14 Correct 8 ms 23828 KB good job!
15 Correct 9 ms 23900 KB good job!
16 Correct 93 ms 35816 KB good job!
17 Correct 92 ms 35860 KB good job!
18 Correct 96 ms 35856 KB good job!
19 Correct 96 ms 35608 KB good job!
20 Correct 94 ms 35836 KB good job!
21 Correct 95 ms 38896 KB good job!
22 Correct 171 ms 43376 KB good job!
23 Correct 9 ms 23896 KB good job!
# Verdict Execution time Memory Grader output
1 Correct 10 ms 24156 KB good job!
2 Correct 9 ms 24156 KB good job!
3 Correct 10 ms 24156 KB good job!
4 Correct 10 ms 24068 KB good job!
5 Correct 10 ms 24152 KB good job!
6 Correct 9 ms 24152 KB good job!
7 Correct 10 ms 24156 KB good job!
8 Correct 10 ms 24156 KB good job!
9 Correct 10 ms 24152 KB good job!
10 Correct 11 ms 24156 KB good job!
11 Correct 10 ms 24412 KB good job!
12 Correct 10 ms 24156 KB good job!
13 Correct 14 ms 24668 KB good job!
14 Correct 9 ms 24156 KB good job!
15 Correct 10 ms 24156 KB good job!
# Verdict Execution time Memory Grader output
1 Correct 631 ms 72428 KB good job!
2 Correct 214 ms 67256 KB good job!
3 Correct 646 ms 79012 KB good job!
4 Correct 365 ms 68688 KB good job!
5 Correct 615 ms 80980 KB good job!
6 Correct 296 ms 66896 KB good job!
7 Correct 381 ms 71012 KB good job!
8 Correct 613 ms 72016 KB good job!
9 Correct 623 ms 85076 KB good job!
10 Correct 604 ms 85328 KB good job!
11 Correct 554 ms 136924 KB good job!
12 Correct 368 ms 67408 KB good job!
13 Correct 557 ms 124244 KB good job!
14 Correct 421 ms 67760 KB good job!
15 Correct 444 ms 92200 KB good job!
16 Correct 335 ms 60832 KB good job!