Submission #992470

#TimeUsernameProblemLanguageResultExecution timeMemory
992470vqpahmadArranging Shoes (IOI19_shoes)C++14
10 / 100
1096 ms5332 KiB
#include<bits/stdc++.h> using namespace std; #ifdef ONPC #include"debug.h" #else #define debug(...) 42 #endif #define ll long long #define pii pair<int,int> #define F first #define S second #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } const int mod = 1e9 + 7; const int MAXN = 1e6 + 15; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3f; long long count_swaps(vector<int> S){ auto a = S; sort(all(a)); int n = sz(a); vector<int> p; for (int x : S) if (x > 0) p.pb(x); vector<int> brut; ll ans = 1e18; do { brut = S; a.clear(); for (int i = 0; i < sz(p); i++){ a.pb(-p[i]); a.pb(p[i]); } bool good = 1; for (int i = 1; i < n; i += 2){ good &= a[i] + a[i - 1] == 0; good &= a[i] > a[i - 1]; } if (!good) continue; ll cost = 0; for (int i = 0; i < n; i++){ if (a[i] == brut[i]) continue; for (int j = i; j < n; j++){ if (a[i] == brut[j]){ for (int k = j; k > i; k--){ cost++; swap(brut[k], brut[k - 1]); } break; } } } ckmin(ans, cost); } while (next_permutation(all(p))); 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...