QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#97319#5662. Distance Calculatoraguo123WA 2ms3332kbC++14665b2023-04-16 17:31:532023-04-16 17:31:57

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-16 17:31:57]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3332kb
  • [2023-04-16 17:31:53]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<map>
using namespace std;
typedef long long LL;
const int N=2e5+10;
int n,T;
int ans;
int a[110],p[110];
int main()
{
    cin>>T;
    while(T--){
        ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)cin>>a[i],p[i]=i;
        for(int i=1;i<=n;i++){
            if(a[i]!=p[i]){
                int t=a[i],pos;
                for(int j=i;j<=n;j++)if(p[j]==t){pos=j;break;}
                ans+=pos-i;
                for(int j=t;j>i;j--)swap(p[j],p[j-1]);
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3332kb

input:

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

output:

2
6
3
8
9

result:

ok 5 lines

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3332kb

input:

4
5
1 3 5 4 2
5
3 1 2 5 4
3
1 2 3
6
5 3 1 6 2 4

output:

4
3
0
9

result:

wrong answer 4th lines differ - expected: '8', found: '9'