Submission #144191

#TimeUsernameProblemLanguageResultExecution timeMemory
144191FelixMPArranging Shoes (IOI19_shoes)C++14
45 / 100
33 ms3576 KiB
#include "shoes.h" using namespace std; typedef long long int ll; long long count_swaps(std::vector<int> s) { int n = s.size(); vector<ll> open = vector<ll>(n+1, 0); vector<bool> openR = vector<bool>(n+1, false); ll copen = 0; ll inv = 0; ll sol = 0; for(int i=0; i < n; ++i) { ll cs = (s[i] > 0) ? s[i] : -s[i]; if(s[i] > 0) { if(open[cs] > 0 and !openR[cs]) { copen--; open[cs]--; sol += copen; if(open[cs] == 0) { } } else { open[cs]++; sol += copen; copen++; if(open[cs] == 1) { openR[cs] = true; } } } else { if(open[cs] > 0 and openR[cs]) { copen--; open[cs]--; sol += copen; inv++; if(open[cs] == 0) { openR[cs] = false; } } else { open[cs]++; sol += copen; copen++; } } } return sol/2+inv; }
#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...