QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#501342 | #2264. Secrets of Legendary Treasure | yzkkai# | WA | 0ms | 3540kb | C++20 | 3.1kb | 2024-08-02 16:58:34 | 2024-08-02 16:58:34 |
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 (i < si(c) && si(q) && j && q.front() < d[j - 1].F) {
res1.push_back(q.front());
q.pop();
while (i < si(c) && c[i].S == 0) {
res1.push_back(c[i].F);
i++;
}
c[i].S--;
if (c[i].S == 0) {
res1.push_back(c[i].F);
i++;
}
}
if (i == si(c) || j == si(d) || si(q) == 0) break;
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 (j < si(d) && si(q) && i && q.front() < c[i - 1].F) {
res2.push_back(q.front());
q.pop();
while (j < si(d) && d[j].S == 0) {
res2.push_back(d[j].F);
j++;
}
d[j].S--;
if (d[j].S == 0) {
res2.push_back(d[j].F);
j++;
}
}
if (i == si(c) || j == si(d) || si(q) == 0) break;
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;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3540kb
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