Submission #398593

#TimeUsernameProblemLanguageResultExecution timeMemory
398593richyrichArranging Shoes (IOI19_shoes)C++17
10 / 100
15 ms19100 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MOD = 1e9+7; const ll N = 2e5+10; const ll inf = 1e9+100; const double eps = 1; int n, a[N]; set<int> L[N], R[N]; ll ans; bool used[N]; long long count_swaps(std::vector<int> s) { /*for(int c : s) printf("%d ", c); printf("\n");*/ ans = 0; n = s.size(); for(int i = 1;i <= n;i++) { a[i] = s[i-1]; if(a[i] < 0) L[-a[i]].insert(i); else R[a[i]].insert(i); } /*for(int i = 1; i <= 2; i++) { printf("left %d:", i); for(int c : L[i]) printf("%d ", c); printf("\n"); } for(int i = 1; i <= 2; i++) { printf("right %d:", i); for(int c : R[i]) printf("%d ", c); printf("\n"); }*/ for(int i = 1; i <= n; i++){ if(used[i]) continue; int pos; if(a[i] < 0) { pos = *R[-a[i]].begin(); L[-a[i]].erase(i); R[-a[i]].erase(pos); ans += pos - i - 1; used[pos] = used[i] = 1; } else { pos = *L[a[i]].begin(); R[a[i]].erase(i); L[a[i]].erase(pos); ans += pos - i; used[pos] = used[i] = 1; } } 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...