QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#501285 | #2264. Secrets of Legendary Treasure | yzkkai# | WA | 0ms | 3624kb | C++20 | 2.5kb | 2024-08-02 16:22:30 | 2024-08-02 16:22:31 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(x) signed(size(x))
using namespace std;
using ll = long long;
using LL = long long;
#define si(x) (int)x.size()
#define F first
#define S second
inline void solve() {
int n, m;
cin >> n >> m;
vector<bool> vis(n + m + 1);
vector<int> a(n), b(m);
for (int i = 0; i < n; i++) cin >> a[i], vis[a[i]] = 1;
for (int i = 0; i < m; i++) cin >> b[i], vis[b[i]] = 1;
int mx1 = *max_element(a.begin(), a.end());
int mx2 = *max_element(b.begin(), b.end());
if (mx1 > mx2) a.push_back(1e9 + 1), b.push_back(1e9);
else a.push_back(1e9), b.push_back(1e9 + 1);
queue<int> q;
for (int i = 1; i <= n + m; i++) {
if (vis[i]) continue;
q.push(i);
}
vector<pair<int, int>> c, d;
int cur = 0;
for (int i = 0; i <= n; i++) {
if (a[i] == 0) cur++;
else {
c.push_back({a[i], cur});
cur = 0;
}
}
for (int i = 0; i <= m; i++) {
if (b[i] == 0) cur++;
else {
d.push_back({b[i], cur});
cur = 0;
}
}
vector<int> res1, res2;
int i = 0, j = 0;
while (i < si(c) && j < si(d) && si(q)) {
if (c[i].F > d[j].F) {
while (si(q) && j && q.front() < d[j - 1].F) {
res1.push_back(q.front());
q.pop();
c[i].S--;
if (c[i].S == 0) i++;
}
if(si(q)) for (int k = 0; k < d[j].S; k++) {
res2.push_back(q.front());
q.pop();
}
res2.push_back(d[j].F);
j++;
} else {
while (si(q) && i && q.front() < c[i - 1].F) {
res2.push_back(q.front());
q.pop();
d[j].S--;
if (d[j].S == 0) j++;
}
if(si(q)) for (int k = 0; k < c[i].S; k++) {
res1.push_back(q.front());
q.pop();
}
res1.push_back(c[i].F);
i++;
}
}
while (si(q)) {
int cur = q.front();
q.pop();
if (i < si(c)) res1.push_back(cur);
else res2.push_back(cur);
}
for (auto x : res1) if (x < 1e9) cout << x << ' ';
cout << '\n';
for (auto x : res2) if (x < 1e9) cout << x << ' ';
cout << '\n';
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3624kb
input:
100 100 1 2 3 4 6 10 11 14 17 18 19 21 24 25 26 27 29 32 34 35 36 37 39 40 44 49 52 53 55 59 65 66 67 68 73 74 81 82 83 85 86 88 89 90 96 98 99 102 103 104 106 107 108 116 117 118 121 124 127 128 129 130 131 132 134 137 138 139 141 145 148 149 152 153 154 156 157 158 161 162 163 167 169 170 173 174 ...
output:
result:
wrong output format Unexpected end of file - int32 expected