제출 #583681

#제출 시각아이디문제언어결과실행 시간메모리
583681joelauArranging Shoes (IOI19_shoes)C++14
50 / 100
1087 ms6220 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; long long N; pair<long long,long long> A[100005], B[100005]; long long count_swaps(vector<int> s) { N = s.size()/2; long long ans = 0; for (long long i = 0; i < N; ++i) { for (long long j = 0; j < N; ++j) A[j] = B[j] = make_pair(4e18,4e18); long long cnt = 0; for (long long j = 0; j < N*2; ++j) { if (s[j] == 0) continue; if (s[j] > 0) A[s[j]-1] = min(A[s[j]-1],make_pair(cnt++,j)); else B[-s[j]-1] = min(B[-s[j]-1],make_pair(cnt++,j)); } pair<long long,long long> x = make_pair(4e18,4e18); for (long long j = 0; j < N; ++j) if (A[j].first != -1 && B[j].first != -1) { long long val = A[j].first + B[j].first; if (B[j].first < A[j].first) val--; x = min(x,make_pair(val,j)); } ans += x.first; s[A[x.second].second] = s[B[x.second].second] = 0; } 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...