QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#278339#6838. Assumption is All You NeedrageOfThunder#WA 0ms3732kbC++142.8kb2023-12-07 15:01:512023-12-07 15:01:52

Judging History

你现在查看的是最新测评结果

  • [2023-12-07 15:01:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3732kb
  • [2023-12-07 15:01:51]
  • 提交

answer

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,fma")
// MagicDark
#include <bits/stdc++.h>
#define debug cerr << "[" << __LINE__ << "] "
#define SZ(x) (int) x.size() - 1
#define all(x) x.begin(), x.end()
#define ms(x, y) memset(x, y, sizeof x)
#define F(i, x, y) for (int i = (x); i <= (y); i++)
#define DF(i, x, y) for (int i = (x); i >= (y); i--)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template <typename T> inline void chkmax(T &x, T y) {x = max(x, y);}
template <typename T> inline void chkmin(T &x, T y) {x = min(x, y);}
template <typename T> inline void read(T &x) {
	x = 0; int f = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
inline void pc(char c) {
	const int BUF = 1e6;
	static char ch[BUF], *r = ch;
	if (!c || r - ch == BUF) fwrite(ch, 1, r - ch, stdout), r = ch;
	*r++ = c;
}
template <typename T> inline void write(T x) {
	T l = 0;
	ull y = 0;
	if (!x) {pc(48); return;}
	if (x < 0) {x = -x; pc('-');}
	while (x) {y = y * 10 + x % 10; x /= 10; ++l;}
	while (l) {pc(y % 10 + 48); y /= 10; --l;}
}
template <typename T> inline void writeln(T x) {write(x); pc('\n');}
template <typename T> inline void writes(T x) {write(x); pc(32);}
const int N = 2050;
int n, a[N], b[N], c[N], tot;
pair <int, int> ans[N * N];
void doit(int x, int y) {
	swap(c[a[x]], c[a[y]]);
	swap(a[x], a[y]);
	ans[++tot] = make_pair(x, y);
}
void zhk() {
	tot = 0;
	read(n);
	F(i, 1, n) read(a[i]), c[a[i]] = i;
	F(i, 1, n) read(b[i]);
	// vector <pair <int, int>> ans;
	F(i, 1, n) {
		if (a[i] < b[i]) {
			writeln(-1);
			return;
		}
		F(j, i + 1, n)
			if (a[j] == b[i]) {
				int pos = j;
				F(k, a[j] + 1, a[i]) {
					int t = c[k];
					if (t < pos) {
						doit(t, pos);
						pos = t;
					}
				}
				// while (pos > i) {
				// 	int p = 0;
				// 	DF(k, pos - 1, i) {
				// 		if (a[k] > a[pos]) {
				// 			if (!p) p = k;
				// 			else if (a[k] < a[p]) p = k;
				// 		}
				// 	}
				// 	doit(p, pos);
				// 	// ans.emplace_back(p, pos);
				// 	pos = p;
				// }
				// bool flag = true;
				// F(k, i + 1, j - 1)
				// 	if (a[k] < a[i] && a[k] > a[j]) {
				// 		swap(a[i], a[k]);
				// 		ans.emplace_back(i, k);
				// 		flag = false;
				// 		break;
				// 	}
				// swap(a[i], a[j]);
				// ans.emplace_back(i, j);
				break;
			}
	}
	writeln(tot);
	F(i, 1, tot) writes(ans[i].first), writeln(ans[i].second);
	// for (auto [i, j]: ans) cout << i << ' ' << j << '\n';
}
signed main() {
	int _ = 1;
	read(_);
	while (_--) zhk();
	return pc(0), 0;
}
/* why?
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

input:

3
2
1 2
2 1
4
4 1 2 3
1 3 2 4
8
8 7 6 5 4 3 2 1
1 8 7 6 5 4 3 2

output:

-1
2
1 2
2 4
7
7 8
6 7
5 6
4 5
3 4
2 3
1 2

result:

ok T=3

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3732kb

input:

315
10
8 4 6 1 2 9 7 5 10 3
6 7 8 10 5 1 3 2 9 4
10
10 8 2 9 6 5 7 4 3 1
7 1 3 5 9 8 4 10 6 2
6
4 6 5 3 1 2
1 5 4 6 2 3
12
5 9 12 8 10 6 11 4 2 3 1 7
9 2 3 1 5 12 4 7 6 10 8 11
10
4 7 3 2 8 9 6 10 5 1
1 4 8 10 3 7 9 6 2 5
7
1 2 4 5 6 7 3
4 3 5 6 7 2 1
3
1 3 2
2 1 3
7
1 5 3 7 6 4 2
6 5 2 1 3 4 7
1
1
...

output:

-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
0
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
4 5
1 4
2 4
-1
-1
-1
-1
-1
-1
0
0
-1
-1
-1
-1
-1
-1
0
0
-1
-1
0
-1
-1
-1
1
1 2
-1
2
1 2
2 3
-1
-1
0
-1
-1
2
2 3
3 4
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
1
1 ...

result:

wrong answer Case #2: Jury has the answer but participant has not