Submission #586576

#TimeUsernameProblemLanguageResultExecution timeMemory
586576VanillaAncient Books (IOI17_books)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long int64;

int64 minimum_walk(vector<int> a, int s) {
	int n = a.size();
	int64 rs = 0;
	for (int i = 0; i < n; i++){
		int sp = 0;
		for (int j = 0; j < n - i - 1; j++){
			if (a[j] > a[j + 1]) {
				swap(a[j], a[j + 1]);
				rs++;
				sp = j;
			}
		}
		for (int j = sp; j >= 1; j--){
			if (a[j] < a[j-1]) {
				swap(a[j], a[j - 1]);
				rs++;
			}
		}
		if (sp == 0) break;
		rs+= sp * 2;
	}
	return rs;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...