#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[0];
for(int i=1; i<=n; i++) cout << " " << a[i];
cout << "\n";
cout << b[1];
for(int i=2; i<=n; i++) cout << " " << b[i];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
161 ms |
39844 KB |
Integer element c_i[1] equals to 0, violates the range [1, 2] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
11 ms |
24152 KB |
Integer element c_i[1] equals to 0, violates the range [1, 134] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
632 ms |
71704 KB |
Integer element c_i[1] equals to 0, violates the range [1, 1996] |
2 |
Halted |
0 ms |
0 KB |
- |