Submission #286272

#TimeUsernameProblemLanguageResultExecution timeMemory
286272BeanZArranging Shoes (IOI19_shoes)C++14
10 / 100
3 ms2688 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; #define ll long long #define endl '\n' const int N = 2e5 + 5; vector<ll> node[100005]; ll a[200005], in[200005]; ll count_swaps(vector<int> s){ ll ans = 0; int n = s.size(); for (int i = 0; i < n; i++){ if (s[i] < 0){ bool flag = false; for (int j = i - 1; j >= 0; j--){ if (((s[j] + s[i]) == 0) && in[j] == 0){ flag = true; ans = ans + i - j; for (int k = i - 1; k >= j; k--){ swap(s[k], s[k + 1]); swap(in[k], in[k + 1]); } in[j + 1] = 1; break; } } if (flag) continue; for (int j = i + 1; j < n; j++){ if ((s[j] + s[i]) == 0 && in[j] == 0){ ans = ans + j - 1 - i; for (int k = i + 1; k < j; k++){ swap(s[k], s[k - 1]); swap(in[k], in[k - 1]); } in[j] = 1; break; } } } } return ans; } /* int main(){ ios_base::sync_with_stdio(false); cin.tie(0); if (fopen("VietCT.INP", "r")){ freopen("VietCT.INP", "r", stdin); freopen("VietCT.OUT", "w", stdout); } ll n; cin >> n; vector<int> mem; for (int i = 1; i <= (2 * n); i++){ ll u; cin >> u; mem.push_back(u); } cout << count_swaps(mem); } */ /* */
#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...