Submission #4260338


Source Code Expand

#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
const int N=1e5+5;
inline int read(){
	int x=0,w=0;char ch=0;
	while(!isdigit(ch)) w|=ch=='-',ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return w?-x:x;
}
int n,ans,a[N];
int main(){
	//freopen("F.in","r",stdin);
	n=read();
	for(int i=1;i<=n;++i) a[i]=read();
	bool fg=0;
	for(int t=1;t<=5000;++t){
		fg=0;
		for(int i=2;i<=n-1;++i)
		 	if(a[i-1]>a[i+1]){
		 		swap(a[i-1],a[i+1]);
		 		fg=1;
			 }
		if(!fg) break;
	}
	
	
	
//	sort(a+1,a+n+1);
//for(int i=1;i<=n;++i) printf("%d ",a[i]);
	for(int i=n;i>=2;--i)
		for(int j=1;j<=i-1;++j)
			if(a[j]>a[j+1]){
				swap(a[j],a[j+1]);++ans;//printf("233");
			}
	int k;
	//for(k=2;k<=n;++k) if(a[k]<a[k-1]) break;
	printf("%d",ans);
	//if(k==n+1) printf(" 1");
	//else printf(" 0");
	return 0;
}

Submission Info

Submission Time
Task C - BBuBBBlesort!
User vjudge2
Language C++14 (GCC 5.4.1)
Score 0
Code Size 845 Byte
Status TLE
Exec Time 2103 ms
Memory 512 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 2
AC × 7
TLE × 17
Set Name Test Cases
Sample s1.txt, s2.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
01.txt TLE 2103 ms 512 KB
02.txt TLE 2103 ms 512 KB
03.txt TLE 2103 ms 512 KB
04.txt TLE 2103 ms 512 KB
05.txt TLE 2103 ms 512 KB
06.txt TLE 2103 ms 512 KB
07.txt TLE 2103 ms 512 KB
08.txt TLE 2103 ms 512 KB
09.txt TLE 2103 ms 512 KB
10.txt TLE 2103 ms 512 KB
11.txt TLE 2103 ms 512 KB
12.txt TLE 2103 ms 512 KB
13.txt TLE 2103 ms 512 KB
14.txt TLE 2103 ms 512 KB
15.txt TLE 2103 ms 512 KB
16.txt TLE 2103 ms 512 KB
17.txt TLE 2103 ms 512 KB
18.txt AC 0 ms 128 KB
19.txt AC 1 ms 128 KB
20.txt AC 1 ms 128 KB
21.txt AC 0 ms 128 KB
22.txt AC 0 ms 128 KB
s1.txt AC 0 ms 128 KB
s2.txt AC 1 ms 128 KB