Submission #824420

#TimeUsernameProblemLanguageResultExecution timeMemory
824420tomrukArranging Shoes (IOI19_shoes)C++17
50 / 100
1083 ms3132 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long count_swaps(vector<int> s){ int n = s.size()/2; long long ans = 0; for(int i = 0;i<n;i++){ int val1 = 1e9; int val2 = 1e9; for(int j = 2*i;j<2*n;j++){ if(s[j] == -s[2*i]){ val1 = j - (2 * i) - 1 + (s[j] < 0); break; } } for(int j = 2*i + 1;j<2*n;j++){ if(s[j] == -s[2*i + 1]){ val2 = j - (2 * i) + (s[j] < 0); break; } } // cout << val1 << ' ' << val2 << endl; ans += min(val1,val2); if(val2 < val1){ swap(s[2*i],s[2*i+1]); } for(int j = 2*i+1;j<2*n;j++){ if(s[j] == -s[2*i]){ for(int c = j;c>2*i + 1;c--){ swap(s[c],s[c-1]); } break; } } if(s[2*i] > 0) swap(s[2*i+1],s[2*i]); // for(auto u:s){ // cout << u << ' '; // } // cout << endl; } 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...