QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#875613 | #7861. Inverse Topological Sort | kian2009 | WA | 1ms | 3712kb | C++14 | 1.1kb | 2025-01-29 23:52:33 | 2025-01-29 23:52:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, a[MAXN], b[MAXN], ind[MAXN];
void input() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
for (int i = 1; i <= n; i++) {
cin >> b[i];
ind[b[i]] = i;
}
}
void findAns() {
vector<pair<int, int>> res;
int mi = -1, ma = -1, x = -1;
bool f = false;
for (int i = 1; i <= n; i++) {
if (!f) {
if (a[i] == b[i]) {
if (i != 1)
res.push_back({a[i - 1], a[i]});
continue;
}
if (a[i] > b[i]) {
cout << "NO" << endl;
return;
}
mi = a[i];
ma = b[i];
x = mi;
f = true;
if (i != 1) {
for (int j = i; j <= n; j++)
res.push_back({a[i - 1], a[j]});
}
continue;
}
if (a[i] < mi || a[i] > ma) {
if (ind[x] >= ind[a[i]]) {
cout << "NO" << endl;
return;
}
res.push_back({x, a[i]});
}
if (ind[a[i]] < ind[x])
x = a[i];
}
cout << res.size() << endl;
for (auto p : res)
cout << p.first << " " << p.second << endl;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
input();
findAns();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3712kb
input:
3 1 2 3 1 2 3
output:
2 1 2 2 3
result:
wrong answer invalid output