제출 #766706

#제출 시각아이디문제언어결과실행 시간메모리
766706khshgArranging Shoes (IOI19_shoes)C++14
30 / 100
1082 ms13208 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using str = string; using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>; #define mp make_pair #define ff first #define ss second #define ar array template<class T> using V = vector<T>; using vi = V<int>; using vb = V<bool>; using vl = V<ll>; using vd = V<ld>; using vs = V<str>; using vpi = V<pi>; using vpl = V<pl>; using vpd = V<pd>; #define sz(x) (int)((x).size()) #define bg(x) begin(x) #define all(x) bg(x), end(x) #define rall(x) (x).rbegin(), (x).rend() #define sor(x) sort(all(x)) #define rsz resize #define ins insert #define pb push_back #define eb emplace_back #define ft front() #define bk back() #define lb lower_bound #define ub upper_bound #define FOR(i, a, b) for(int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for(int i = (b) - 1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define rep(a) F0R(_, a) #define trav(a, x) for(auto& a : x) template<class T> bool ckmin(T& a, const T& b) { return (b < a ? a = b, 1 : 0); } template<class T> bool ckmax(T& a, const T& b) { return (b > a ? a = b, 1 : 0); } ll count_swaps(vi S) { int N = sz(S) >> 1; { map<int, int> c; trav(u, S) c[abs(u)]; int tim3 = 1; trav(u, c) u.ss = tim3++; trav(u, S) u = c[abs(u)] * (u < 0 ? -1 : 1); } vi A; trav(u, S) if(u > 0) A.eb(u); sor(A); ll ans = 0x3f3f3f3f; do { V<vi> l(N + 1), r(N + 1); F0R(i, 2 * N) { if(S[i] < 0) l[-S[i]].eb(i); else r[S[i]].eb(i); } ll cur = 0; F0R(i, N) { int lsh = 2 * i; int dis = 0x3f3f3f3f, ind = -1; F0R(j, sz(l[A[i]])) { if(ckmin(dis, abs(lsh - l[A[i]][j]))) ind = j; } if(ind == -1) { cout << "wtf\n"; exit(1); } cur += dis; FOR(j, 1, N + 1) { trav(u, l[j]) if(u < l[A[i]][ind]) ++u; trav(u, r[j]) if(u < l[A[i]][ind]) ++u; } l[A[i]].erase(bg(l[A[i]]) + ind); lsh = 2 * i + 1; dis = 0x3f3f3f3f, ind = -1; F0R(j, sz(r[A[i]])) { if(ckmin(dis, abs(lsh - r[A[i]][j]))) ind = j; } if(ind == -1) { cout << "wtf\n"; exit(1); } cur += dis; FOR(j, 1, N + 1) { trav(u, l[j]) if(u < r[A[i]][ind]) ++u; trav(u, r[j]) if(u < r[A[i]][ind]) ++u; } r[A[i]].erase(bg(r[A[i]]) + ind); } ckmin(ans, cur); } while(next_permutation(all(A))); 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...