Submission #233581

#TimeUsernameProblemLanguageResultExecution timeMemory
233581BasilhijazArranging Shoes (IOI19_shoes)C++17
30 / 100
1088 ms2148 KiB
#include "shoes.h" using namespace std; typedef long long ll; #define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define mp make_pair #define pb push_back #define lp(i,s,f) for(ll i = s; i < ll(f); i++) #define inF freopen("input.in", "r", stdin); #define outF freopen("output.in", "w", stdout); #define endl '\n' #define MOD 1000000007 long long count_swaps(vector<int> s) { int n = s.size(); vector<pair<int, int> > v; bool done[n]; for(int i = 0; i < n; i++){ done[n] = 0; } for(int i = 0; i < n; i++){ if(!done[i]){ int serach = s[i]*-1; int first = -1; int second = -1; first = i; for(int j = i + 1; j < n; j++){ if(s[j] == serach && !done[j]){ second = j; done[j] = 1; break; } } v.pb({first, second}); } } ll ans = 0; for(int i = 0; i < n; i++){ done[n] = 0; } for(int i = 0; i < n/2; i++){ if(s[v[i].first] > s[v[i].second]){ ans++; } } int pos[n]; for(int i = 0; i < n/2; i++){ pos[v[i].first] = v[i].first; pos[v[i].second] = v[i].second; } for(int i = 0; i < n/2; i++){ pos[v[i].second] = v[i].first + 1; for(int j = v[i].first + 1; j < v[i].second; j++){ if(pos[j] > v[i].first && pos[j] < v[i].second)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...