제출 #1305820

#제출 시각아이디문제언어결과실행 시간메모리
1305820ayazArranging Shoes (IOI19_shoes)C++20
50 / 100
100 ms12160 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; #define isz(x) (int)x.size() long long count_swaps(std::vector<int> s) { vector<int> a = s; int n = isz(a); #define int long long bool ok = true; set<int> st; for (int i = 0; i < n / 2; i++) { ok &= (a[i] + a[i + n / 2] == 0); ok &= (a[i] < 0); st.insert(abs(a[i])); } if (ok) { return (n / 2) * (n / 2 - 1) / 2; } if (isz(st) == 1) { int ans = 0; set<int> pos[2]; for (int i = 0; i < n; i++) { pos[a[i] < 0 ? 0 : 1].insert(i); } for (int i = 0; i < n; i++) { if (i % 2 == 0 && a[i] > 0) { auto it = pos[0].upper_bound(i); ans += *it - i; swap(a[i], a[*it]); pos[0].erase(it); pos[1].erase(pos[1].find(i)); pos[0].insert(i); pos[1].insert(*it); continue; } if (i % 2 == 1 && a[i] < 0) { auto it = pos[1].upper_bound(i); ans += *it - i; swap(a[i], a[*it]); pos[1].erase(it); pos[0].erase(pos[0].find(i)); pos[1].insert(i); pos[0].insert(*it); } } return ans; } if (n == 2) { return (a[0] > 0); } a = s; int ans = 0; for (int i = 0; i < n; i++) { if (i % 2 == 0 && a[i] > 0) { int d = 1e9; for (int j = i + 1; j < n; j++) { if (a[j] + a[i] == 0) { d = j; break; } } ans += (d - i); for (int j = d; j > i; j--) swap(a[j], a[j - 1]); continue; } if (i % 2 == 1 && (a[i] < 0 || (a[i - 1] + a[i]) != 0)) { int d = 1e9; for (int j = i + 1; j < n; j++) { if (a[j] + a[i - 1] == 0) { d = j; break; } } ans += (d - i); for (int j = d; j > i; j--) swap(a[j], a[j - 1]); } } for (int i = 0; i < n; i += 2) { ans += (a[i] > 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...