QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#589621 | #5305. Oscar is All You Need | louhao088 | WA | 0ms | 3788kb | C++23 | 1.9kb | 2024-09-25 19:05:36 | 2024-09-25 19:05:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N = 1050;
int n, p[N], tmp[N], id[N];
vector <pair<int, int> > s;
int flag;
void work(int x, int y) {
s.push_back(make_pair(x, y));
tmp[0] = 0;
for (int i = n - y + 1; i <= n; i++) tmp[++tmp[0]] = p[i];
for (int i = x + 1; i <= n - y; i++) tmp[++tmp[0]] = p[i];
for (int i = 1; i <= x; i++) tmp[++tmp[0]] = p[i];
for (int i = 1; i <= n; i++) p[i] = tmp[i], id[p[i]] = i;
// printf("%d %d\n", x, y);
// for (int i = 1; i <= n; i++) printf("%d ", p[i]); printf("\n");
}
void write() {
bool mor = 0;
if (p[n] != n) mor = 1;
printf("%d\n", s.size() + mor);
for (int i = 0; i < s.size(); i++) {
printf("%d %d\n", s[i].first, s[i].second);
if (mor && i == flag) printf("1 1\n");
}
}
void slove() {
s.clear();
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &p[i]), id[p[i]] = i;
if (n == 3) {
if (p[1] > p[3]) work(1, 1);
write(); return ;
}
flag = 0;
if (id[n] == id[n - 1] + 1 || id[n - 1] == id[n] + 1) {
int l = min(id[n], id[n - 1]), r = max(id[n], id[n - 1]);
if (r != n) work(l, 1);
else work(1, 1);
flag = 1;
}
work(min(id[n], id[n - 1]), n - max(id[n], id[n - 1]) + 1);
if (p[1] != 1) {
work(id[1] - 1, n - id[1]);
work(id[1] - 2, n - id[1] + 1);
}
for (int i = 2; i <= n - 2; i++) {
if (p[i] == i) continue;
if (id[i] == n) {
work(i - 1, 2);
work(1, i - 1);
}
else {
work(i - 1, 1);
work(id[i] - 1, i - 1);
}
}
// for (int i = 1; i <= n - 2; i++)
// assert(p[i] == i);
// for (int i = 1; i <= n; i++) printf("%d ", p[i]);
// printf("\n");
write();
}
int main() {
int t; scanf("%d", &t);
while (t--) slove();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3788kb
input:
2 3 1 3 2 5 4 1 2 3 5
output:
1 6 1 1 1 1 1 3 2 2 1 1 3 1
result:
wrong answer Integer parameter [name=x] equals to 6, violates the range [1, 3]