QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#716941 | #5662. Distance Calculator | tsogsummit# | RE | 0ms | 0kb | C++14 | 439b | 2024-11-06 16:26:36 | 2024-11-06 16:26:37 |
answer
#include <bits/stdc++.h>
using namespace std;
int main(){
int t;
cin >> t;
while(t--){
int n;
int i , j , k;
cin >> n;
int a[n];
int sum = 0;
for(int i = 1 ; i <= n ; i++){
cin >> a[i];
}
for(i = n ; i >= 1 ; i--){
for(j = 1 ; j <= n ; j++){
if(a[j] == i){
for(k = j ; k < i ; k++){
sum++;
swap(a[k] , a[k + 1]);
}
}
}
}
cout << sum << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
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