제출 #769680

#제출 시각아이디문제언어결과실행 시간메모리
769680SanguineChameleonArranging Shoes (IOI19_shoes)C++17
50 / 100
1084 ms16484 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 20; int order[maxN * 2]; int sizes[maxN * 2]; int match[maxN * 2]; bool flag[maxN * 2]; vector<int> shoes[maxN][2]; long long count_swaps(vector<int> _sizes) { int n = (int)_sizes.size() / 2; for (int i = 1; i <= n * 2; i++) { sizes[i] = _sizes[i - 1]; if (sizes[i] < 0) { shoes[-sizes[i]][0].push_back(i); } else { shoes[sizes[i]][1].push_back(i); } } for (int i = 1; i <= n; i++) { for (int j = 0; j < (int)shoes[i][0].size(); j++) { match[shoes[i][0][j]] = shoes[i][1][j]; match[shoes[i][1][j]] = shoes[i][0][j]; } } int cnt = 0; for (int i = 1; i <= n * 2; i++) { if (!flag[i]) { order[i] = cnt + (sizes[i] < 0 ? 1 : 2); order[match[i]] = cnt + (sizes[match[i]] < 0 ? 1 : 2); flag[i] = true; flag[match[i]] = true; cnt += 2; } } int res = 0; for (int i = 1; i <= n * 2; i++) { for (int j = i + 1; j <= n * 2; j++) { if (order[i] > order[j]) { res++; } } } return res; }
#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...