제출 #586004

#제출 시각아이디문제언어결과실행 시간메모리
586004ZaniteArranging Shoes (IOI19_shoes)C++17
10 / 100
1086 ms138572 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define fi first #define se second ll count_swaps(vector<int> s) { int n = s.size(); vector<int> rel(n); deque<int> occ[n+1] = {}; deque<pii> leftShoes; for (int i = 0; i < n; i++) { if (s[i] < 0) leftShoes.push_back({i, -s[i]}); else occ[s[i]].push_back(i); } int placed = 0; for (auto &[idx, typ] : leftShoes) { rel[idx] = placed++; rel[occ[typ].front()] = placed++; occ[typ].pop_front(); } int ans = 0; for (int i = 0; i < n; i++) { for (int j = i; j > 0; j--) { if (rel[j] < rel[j-1]) { swap(rel[j], rel[j-1]); ans++; } } } return ans; } // Grader #ifdef Zanite int main() { int n; assert(1 == scanf("%d", &n)); vector<int> S(2 * n); for (int i = 0; i < 2 * n; i++) assert(1 == scanf("%d", &S[i])); fclose(stdin); long long result = count_swaps(S); printf("%lld\n", result); fclose(stdout); return 0; } #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...