제출 #1205985

#제출 시각아이디문제언어결과실행 시간메모리
1205985jer033Arranging Shoes (IOI19_shoes)C++20
45 / 100
146 ms13944 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; ll inversion_count(vector<int> s) { int n = s.size(); if (n<=1) return 0; vector<int> l; vector<int> r; for (int i=0; i<(n/2); i++) l.push_back(s[i]); for (int i=n/2; i<n; i++) r.push_back(s[i]); ll k = 0; ll m = 0; ll ans = inversion_count(l) + inversion_count(r); sort(l.begin(), l.end()); sort(r.begin(), r.end()); while ((k<(n/2)) and (m<((n+1)/2))) { if (l[k] > r[m]) { ll add = (n/2) - k; ans += add; m++; } else k++; } return ans; } long long count_swaps(std::vector<int> s) { int n = (s.size())/2; vector<int> left_shoe_count(n+1, 0); vector<int> right_shoe_count(n+1, 0); map<pii, int> renumber; vector<int> new_s(2*n); int c = 1; for (int i=0; i<(2*n); i++) if (s[i] < 0) { left_shoe_count[0-s[i]]++; renumber[{0-s[i], left_shoe_count[0-s[i]]}] = c; new_s[i] = c; c+=2; } for (int i=0; i<(2*n); i++) if (s[i] > 0) { right_shoe_count[s[i]]++; new_s[i] = 1 + renumber[{s[i], right_shoe_count[s[i]]}]; } return inversion_count(new_s); }
#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...