QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#716941#5662. Distance Calculatortsogsummit#RE 0ms0kbC++14439b2024-11-06 16:26:362024-11-06 16:26:37

Judging History

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

  • [2024-11-06 16:26:37]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-06 16:26:36]
  • 提交

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

result: