Submission #1165830

#TimeUsernameProblemLanguageResultExecution timeMemory
1165830SG2AlokArranging Shoes (IOI19_shoes)C++20
10 / 100
0 ms328 KiB
#include "shoes.h"
#include <bits/stdc++.h>
using namespace std;

long long count_swaps(std::vector<int> s) {
	long long ans = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] < 0){
			if(i != s.size() - 1 && s[i] == -s[i + 1]){
				continue;
			}
			
			int pos = -1;
			for(int j = 0; j < s.size(); j++){
				if(j == 0 && s[j] == -s[i]){
					pos = j;
					break;
				} else if(s[j] == -s[i] && s[j - 1] != -s[j]){
					pos = j;
					break;
				}
			}
			
			if(pos == -1) continue;
//			cout << pos << " " << i << endl;
			
			while(pos < i){
				swap(s[pos], s[pos + 1]);
				pos++;
				ans++;
			}
			
			while(pos > i + 1){
				swap(s[pos], s[pos - 1]);
				pos--;
				ans++;
			}
		}
	}
	
	return ans;
}
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...