제출 #575406

#제출 시각아이디문제언어결과실행 시간메모리
575406webArranging Shoes (IOI19_shoes)C++17
50 / 100
1079 ms4660 KiB
#include "shoes.h" #include <iostream> #include <vector> #include <tuple> #include <algorithm> using namespace std; long long count_swaps(std::vector<int> s) { int n = s.size()/2; vector<pair<int, bool>>shoes(2*n); for(int i =0 ; i<2*n; ++i) { shoes[i] = {abs(s[i]), s[i] < 0}; } long long numSwaps = 0; //sort(shoes.begin(), shoes.end()); int currShoe = 0; while(currShoe < 2*n) { int findShoe = shoes[currShoe].first; int findShoeSign = !(shoes[currShoe].second); pair<int, bool> lastEl = {findShoe, findShoeSign}; for(int i = 1; i<(2*n-currShoe); ++i) { swap(lastEl, shoes[currShoe+ i]); if(lastEl.first == findShoe && lastEl.second == findShoeSign) { //found break; } numSwaps++; } if(shoes[currShoe].second == 0) { numSwaps++; swap(shoes[currShoe], shoes[currShoe+1]); } currShoe+=2; } return numSwaps; }
#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...