Submission #559888

#TimeUsernameProblemLanguageResultExecution timeMemory
559888cegaxArranging Shoes (IOI19_shoes)C++17
10 / 100
1 ms304 KiB
#include <bits/stdc++.h> using namespace std; #define all(c) (c).begin(), (c).end() #define rall(A) A.rbegin(),A.rend() #define pb push_back #define dbg(x) do {cerr << #x <<" = " << (x) << endl; } while (false) typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; //cout << setprecision(12) << fixed; ll count_swaps(vector<int> s) { ll ans = 0; int n = s.size() >> 1; vi L[n+1], R[n+1]; for(int i = 0; i < 2 * n; i++) { cin >> s[i]; if(s[i] < 0) L[-s[i]].pb(i+1); else R[s[i]].pb(i+1); } int a[2*n + 1]; bool vis[2 * n + 1]; memset(vis, 0, sizeof(vis)); int ind = 1; for(int i = 2 * n - 1; i >= 0; i--) { if(vis[i]) continue; int l, r; l = L[abs(s[i])].back(); r = R[abs(s[i])].back(); vis[l-1] = vis[r-1] = 1; L[abs(s[i])].pop_back(); R[abs(s[i])].pop_back(); if(l > r) ans++; a[l] = a[r] = ind; ans += abs(r-l)-1; ind++; } return ans; } // int main() { // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); // // return 0; // } //
#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...