제출 #692476

#제출 시각아이디문제언어결과실행 시간메모리
692476zeroesandonesArranging Shoes (IOI19_shoes)C++17
10 / 100
3 ms304 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; using ll = long long; using vi = vector<long long>; #define pb emplace_back long long count_swaps(vector<int> s) { int n = (s.size()); ll ans = 0; int change[n] = {}; set<int> L[n + 5], R[n + 5]; bool done[n] = {}; for(int i = 0; i < n; ++i) { if(s[i] < 0) { L[-s[i]].insert(i); } else { R[s[i]].insert(i); } } for(int i = 0; i < n; ++i) { if(done[i]) continue; if(s[i] < 0) { L[-s[i]].erase(L[-s[i]].begin()); auto it = *R[-s[i]].begin(); for(int j = i; j <= it; ++j) { ans += change[j]; } done[it] = true; for(int j = i + 1; j <= it; ++j) { ++change[j]; } R[-s[i]].erase(R[-s[i]].begin()); } else { ++ans; R[s[i]].erase(R[s[i]].begin()); auto it = *L[s[i]].begin(); for(int j = i; j <= it; ++j) { ans += change[j]; } done[it] = true; for(int j = i + 1; j <= it; ++j) { ++change[j]; } L[s[i]].erase(L[s[i]].begin()); } } 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...