QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#274660#6838. Assumption is All You NeedSatsukiWA 1ms5744kbC++201.7kb2023-12-03 19:42:462023-12-03 19:42:49

Judging History

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

  • [2023-12-03 19:42:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5744kb
  • [2023-12-03 19:42:46]
  • 提交

answer

// #pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10, M = 5e3 + 10, MAXN = 1e5 + 10;
#define endl '\n'
#define int long long

int a[MAXN], b[MAXN];
int st[MAXN][2];
int n;

signed main()
{
    int T;
    cin >> T;
    while(T --)
    {
        int ok(1), cnt(0);
        cin >> n;
        for(int i = 1; i <= n; ++ i) cin >> a[i];
        for(int i = 1; i <= n; ++ i) cin >> b[i];
        for(int i = n; i >= 1; -- i)
        {
            if(!ok)
            {
                cout << "-1" << endl;
                break;
            }
            if(a[i] > b[i]) 
            {
                ok = 0;
                continue;
            }
            if(a[i] == b[i]) continue;
            int pos;
            for(int j = max(1ll, i - 1); j >= 1; -- j)
            {
                if(a[j] == b[i]) pos = j;
            }
            int mx(0), mxp(0);
            for(int j = pos + 1; j <= i - 1; ++ j)
            {
                if(a[j] >= a[pos] || a[j] <= a[i]) continue;
                if(a[j] > mx)
                {
                    mx = a[j];
                    mxp = j;
                }
            }
            if(mx)
            {
                swap(a[mxp], a[pos]);
                st[++cnt][0] = mxp;
                st[cnt][1] = pos;
                swap(mxp, pos);
            }
            if(pos != i)
            {
                st[++cnt][0] = pos;
                st[cnt][1] = i;
                swap(a[pos], a[i]);
            }
        }
        if(!ok) continue;
        cout << cnt << endl;
        for(int i = 1; i <= cnt; ++ i)
        {
            cout << st[i][0] << " " << st[i][1] << endl;
        }
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5688kb

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 4
1 2
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: 5744kb

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
5
4 6
4 5
3 2
3 4
1 3
-1
-1
-1
-1
-1
0
-1
-1
-1
3
2 6
4 5
1 2
-1
-1
-1
0
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
3
4 5
2 4
1 2
-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
6
3 6
3 2
3 5
3 2
3 4
1 3
2
1 3
1 2
-1
-1
0
-1
-1
2
2 4
2 3
-1
-1
-1
0
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-...

result:

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