Submission #837886

#TimeUsernameProblemLanguageResultExecution timeMemory
837886DarkMatterArranging Shoes (IOI19_shoes)C++17
50 / 100
1097 ms2668 KiB
#include<bits/stdc++.h> #include "shoes.h" using namespace std; long long count_swaps(std::vector<int> v) { int n = v.size(); bool ok = true; for (int i = 0; i < n / 2; i++) { if (v[i] > 0 || v[i] != v[i + (n / 2)]) { ok = false; break; } } for (int i = n / 2; i < n; i++) { if (v[i] < 0) { ok = false; break; } } if (ok) { n /= 2; long long ans = 0; for (int i = 0; i < n; i++) ans += i; return ans; } vector<bool>vis(n, false); long long ans = 0; vector<int>idx(n); iota(idx.begin(), idx.end(), 0); for (int i = 0; i < n; i++) { if (vis[i] || (idx[i] & 1 && v[i] > 0)) continue; vis[i] = true; for (int j = i + 1; j < n; j++) { if (!vis[j] && v[j] == -v[i]) { vis[j] = true; int dif = idx[j] - idx[i] - 1; if (idx[i] % 2 == 0 && v[i] < 0) ans += dif; else ans += dif + 1; break; } idx[j]++; } } 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...