제출 #143197

#제출 시각아이디문제언어결과실행 시간메모리
143197mlyean00Arranging Shoes (IOI19_shoes)C++17
70 / 100
1012 ms153452 KiB
#include <bits/stdc++.h> #include "shoes.h" using namespace std; using ll = long long; int sgn(int x) { if (x == 0) return 0; return x > 0 ? 1 : -1; } ll count_inversions(vector<int>& v, int l, int r) { if (r - l == 1) return 0; int mid = (l + r) / 2; ll ans = count_inversions(v, l, mid) + count_inversions(v, mid, r); int l_ptr = l, r_ptr = mid; vector<int> m; m.reserve(r - l); while (l_ptr < mid || r_ptr < r) { if (l_ptr == mid) { m.push_back(v[r_ptr++]); } else if (r_ptr == r) { ans += r_ptr - mid; m.push_back(v[l_ptr++]); } else if (v[l_ptr] <= v[r_ptr]) { ans += r_ptr - mid; m.push_back(v[l_ptr++]); } else { m.push_back(v[r_ptr++]); } } copy(m.begin(), m.end(), v.begin() + l); return ans; } ll count_swaps(vector<int> s) { int n = s.size() / 2; vector<int> t; map<int, int> cnt; for (int i = 0; i < 2 * n; ++i) { int sz = abs(s[i]); if (cnt[sz] == 0 || sgn(s[i]) == sgn(cnt[sz])) { t.push_back(-sz); t.push_back(sz); } cnt[sz] += sgn(s[i]); } assert(t.size() == 2 * n); map<int, stack<int>> m; for (int i = 2 * n - 1; i >= 0; --i) { m[s[i]].push(i); } vector<int> perm(2 * n); for (int i = 0; i < 2 * n; ++i) { perm[i] = m[t[i]].top(); m[t[i]].pop(); } return count_inversions(perm, 0, 2 * n); }

컴파일 시 표준 에러 (stderr) 메시지

In file included from /usr/include/c++/7/cassert:44:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:33,
                 from shoes.cpp:1:
shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:56:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     assert(t.size() == 2 * n);
            ~~~~~~~~~^~~~~~~~
#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...