Submission #837887

#TimeUsernameProblemLanguageResultExecution timeMemory
837887DarkMatterArranging Shoes (IOI19_shoes)C++14
50 / 100
1091 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; i++) { if (i < n / 2 && (v[i] > 0 || (abs(v[i]) != abs(v[i + n])))) { ok = false; break; } else if (i >= n / 2 && 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...