Submission #415685

#TimeUsernameProblemLanguageResultExecution timeMemory
415685MlxaArranging Shoes (IOI19_shoes)C++14
50 / 100
1094 ms26116 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define all(x) x.begin(), x.end() #define mp make_pair #define mt make_tuple #define x first #define y second #include "shoes.h" ll count_swaps(vector<int> s) { map<int, vector<int>> open, close; vector<pair<int, int>> pairs; for (int i = 0; i < (int)s.size(); ++i) { if (s[i] < 0) { open[abs(s[i])].push_back(i); } else { close[abs(s[i])].push_back(i); } } for (auto xop : open) { const vector<int> &op = xop.y; const vector<int> &cl = close[xop.x]; assert(op.size() == cl.size()); for (int i = 0; i < (int)op.size(); ++i) { pairs.emplace_back(op[i], cl[i]); } } ll answer = 0; for (auto &e : pairs) { if (e.x > e.y) { ++answer; swap(e.x, e.y); } // cout << "# " << e.x << " " << e.y << endl; } for (int i = 0; i < (int)pairs.size(); ++i) { for (int j = i + 1; j < (int)pairs.size(); ++j) { int a = pairs[i].x, b = pairs[i].y, c = pairs[j].x, d = pairs[j].y; if (a > c) { swap(a, c), swap(b, d); } assert(a < c); assert(a < b && c < d); if (a < b && b < c && c < d) { answer += 0; } else if (a < c && c < b && b < d) { answer += 1; } else if (a < c && c < d && d < b) { answer += 2; } else { assert(false); } } } return answer; } #ifdef LC #include "grader.cpp" #endif
#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...