Submission #1020760

#TimeUsernameProblemLanguageResultExecution timeMemory
1020760KasymKArranging Shoes (IOI19_shoes)C++17
85 / 100
1034 ms2648 KiB
#include "bits/stdc++.h" using namespace std; #define pb push_back #define ll long long #define ff first #define ss second #define all(v) v.begin(), v.end() #include "bits/stdc++.h" using namespace std; #define ll long long #define ff first #define ss second #define all(v) v.begin(), v.end() ll count_swaps(vector<int> v){ int n = (int)v.size(), ok = 1; n >>= 1; for(int i = 0; i < n; ++i) ok &= (v[i] < 0); for(int i = 0; i < n; ++i) ok &= (-v[i] == v[i+n]); ll ans = 0; if(ok){ n--; ans = n*1ll*(n+1)/2; return ans; } n <<= 1; ok = 1; for(int i = 1; i < n; ++i) ok &= (abs(v[0]) == abs(v[i])); if(ok){ int ne_ = 1, ne__ = 1; for(int i = 0; i < n; ++i){ ne_ = max(i+1, ne_); ne__ = max(i+1, ne__); if(!(i&1)){ if (v[i] < 0) continue; while(v[ne_] > 0) ne_++; swap(v[i], v[ne_]); ans += (ne_-i); } if(i&1){ if(v[i] > 0) continue; while (v[ne__] < 0) ne__++; swap(v[i], v[ne__]); ans += (ne__-i); } } return ans; } vector<int> vis(n, 0); auto match = [&](int i, int j){ vis[j] = 1; for(int k = i+1; k < j; ++k) ans += (!vis[k]); }; for(int i = 0; i < n-1; i++){ if(vis[i]) continue; if(v[i] > 0) ans++; int j = i+1; while(j < n){ if(-v[i] == v[j] and !vis[j]) break; j++; } match(i, 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...