Submission #774768

#TimeUsernameProblemLanguageResultExecution timeMemory
774768Sandarach151Arranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms300 KiB
#include<bits/stdc++.h> #include "shoes.h" using namespace std; long long count_swaps(std::vector<int> s) { int n = s.size()/2; stack<int> negative[n+1]; stack<int> positive[n+1]; long long ans = 0; for(int i=0; i<2*n; i++){ if(s[i]<0){ if(!positive[-1*s[i]].empty()){ ans+= i-positive[-1*s[i]].top(); positive[-1*s[i]].pop(); } else{ negative[-1*s[i]].push(i); } } else{ if(!negative[s[i]].empty()){ ans+= i-negative[s[i]].top()-1; negative[s[i]].pop(); } else{ positive[s[i]].push(i); } } } 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...