Submission #146672

#TimeUsernameProblemLanguageResultExecution timeMemory
146672abacabaArranging Shoes (IOI19_shoes)C++14
10 / 100
2 ms376 KiB
#include <cstdio> #include <cassert> #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> #include <vector> #include <stack> #include <map> #include "shoes.h" using namespace std; const int N = 2e5 + 15; int n, a[N]; map <int, bool> used; map <int, stack <int> > ord; long long count_swaps(vector<int> s) { n = s.size(); long long ans = 0; for(int i = 0; i < n; ++i) a[i + 1] = s[i]; for(int i = n; i; --i) ord[a[i]].push(i); for(int i = 1; i < n; ++i) { if(ord[a[i]].empty() || ord[a[i]].top() != i) continue; ord[a[i]].pop(); int j = ord[-a[i]].top(); ord[-a[i]].pop(); if(a[i] < 0) ans += j - i - 1; else ans += j - 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...