이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define x first
#define y second
#define all(a) (a).begin(), (a).end()
int main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
ll ans = 0;
vector<pair<int, int>> v;
for (int i = 0; i < 2 * n; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
if (x < 0) {
ans += -x;
x = 0;
}
if (x > n - 1) {
ans += x - n + 1;
x = n - 1;
}
if (y < 0) {
ans += -y;
y = 0;
}
if (y > 1) {
ans += y - 1;
y = 1;
}
v.push_back({x, y});
}
sort(v.begin(), v.end());
ll mn = 1e18;
for (int mask = 0; mask < (1 << (2 * n)); mask++) {
vector<int> a, b;
for (int i = 0; i < 2 * n; i++) {
int y = v[i].y ^ ((mask >> i) & 1);
if (y) {
a.push_back(v[i].x);
} else {
b.push_back(v[i].x);
}
}
if (a.size() != n) continue;
ll s = __builtin_popcount(mask);
for (int i = 0; i < n; i++) {
s += abs(a[i] - i);
s += abs(b[i] - i);
}
mn = min(mn, s);
}
ans += mn;
cout << ans << endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
joi2019_ho_t4.cpp: In function 'int main()':
joi2019_ho_t4.cpp:57:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
57 | if (a.size() != n) continue;
| ~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |