QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#97319 | #5662. Distance Calculator | aguo123 | WA | 2ms | 3332kb | C++14 | 665b | 2023-04-16 17:31:53 | 2023-04-16 17:31:57 |
Judging History
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;
}
詳細信息
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'