Submission #992469

#TimeUsernameProblemLanguageResultExecution timeMemory
992469vqpahmadArranging Shoes (IOI19_shoes)C++14
10 / 100
1095 ms3532 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> brut; ll ans = 1e18; do { brut = S; 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(a))); 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...