Submission #618957

#TimeUsernameProblemLanguageResultExecution timeMemory
618957serizeArranging Shoes (IOI19_shoes)C++17
30 / 100
61 ms2104 KiB
#include "shoes.h" #include <bits/stdc++.h> #include <cstdio> #include <cassert> #define all(x) x.begin(),x.end() using namespace std; long long count_swaps(std::vector<int> s) { int n = (int)s.size(); if(n <= 16){ vector<int> neg; for(int i = 0; i < n; i++){ if(s[i] < 0){ neg.push_back(i); } } const int MAX = 16; bitset<MAX> mark; int ans = INT32_MAX; do{ mark.reset(); vector<int> ar(n); int aux = 0; for(int i = 0; i < n/2; i++){ ar[aux] = neg[i]; for(int j = 0; j < n; j++){ if(mark[j] == false and s[j] == -s[ar[aux]]){ ar[aux+1] = j; mark[j] = true; break; } } aux += 2; } vector<int> pos(n), num(n); for(int i = 0; i < n; i++) pos[i] = num[i] = i; /*for(int i = 0; i < n; i++){ cout << ar[i] << " "; }*/ //cout << "\n"; int swp = 0; for(int i = 0; i < n; i++){ swp += abs(i-pos[ar[i]]); //cout << "sumo: " << abs(i-pos[ar[i]]) << "\n"; if(pos[ar[i]] < i){ for(int j = pos[ar[i]]+1; j <= i; j++){ pos[ num[j] ]--; } pos[ ar[i] ] = i; } if(i < pos[ar[i]]){ for(int j = pos[ar[i]]-1; j >= i; j--){ pos[num[j]]++; } pos[ ar[i] ] = i; } for(int i = 0; i < n; i++) num[pos[i]] = i; /*cout << "asi queda el nuevo arr: " << "\n"; for(int i = 0; i < n; i++) cout << num[i] << " "; cout << "\n";*/ } //cout << "\n" << swp << "\n"; ans = min(ans,swp); }while(next_permutation(all(neg))); return ans; } return 0; }
#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...