제출 #244816

#제출 시각아이디문제언어결과실행 시간메모리
244816crossing0verArranging Shoes (IOI19_shoes)C++17
0 / 100
4 ms256 KiB
#include<bits/stdc++.h> #define ll long long //#include "shoes.h" 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; }
#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...