Submission #244820

#TimeUsernameProblemLanguageResultExecution timeMemory
244820crossing0verArranging Shoes (IOI19_shoes)C++17
50 / 100
1095 ms19624 KiB
#include<bits/stdc++.h> #define ll long long #ifndef local #include "shoes.h" #endif using namespace std; ll count_swaps(vector<int> a) { int n = a.size(); ll ans = 0; vector< vector<vector<int>> > v(2,vector< vector<int> >(n+1)); for (int i = 0;i < n; i++) { if (a[i] < 0) v[1][-a[i]].push_back(i); else v[0][a[i]].push_back(i); } vector<int> vis(n,1); for (int i = 1; i <= n; i++) for (int t = 0; t < 2; t++) reverse(v[t][i].begin(),v[t][i].end()); for (int i = 0; i < n;i++) { if (vis[i] == 0) continue; int x = a[i]; int val = abs(x); int t = (x < 0 ? 0 : 1); int ps = v[t][val].back(); vis[i] = 0; v[t][val].pop_back(); v[!t][val].pop_back(); for (int j = i + 1; j < ps; j++) ans += vis[j]; if (t == 1) ans++; vis[ps] = 0; } return ans; } #ifdef local main() { int n; cin >> n; vector<int> v(n); for (int i = 0;i < n; i++) cin >> v[i]; cout << count_swaps(v); } #endif
#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...