이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector <ll> vi;
typedef pair <int,int> pi;
#define pb push_back
#define f first
#define s second
#define OO 1e9
#define all(x) (x).begin(), (x).end()
int main() {
ios::sync_with_stdio(0); cin.tie(0);
// freopen("art2.in", "r", stdin);
// freopen("art2.out", "w", stdout);
int n, k; cin >> k >> n;
vector <pi> home(n), work(n);
for(int i=0; i<n; ++i){
int h, w;char a, b; cin >> a >> h >> b >> w;
home[i].f = h; home[i].s = (a == 'A');
work[i].f = w; work[i].s = (b == 'A');
}
vi v;
for(int i=0; i<n; ++i){
if(home[i].s == work[i].s){ continue; }
v.pb(home[i].f); v.pb(work[i].f);
}
sort(all(v));
v.resize(unique(all(v)) - v.begin());
int median = v[(v.size()-1)/2];
vi ans(10000);
for(int i=0; i<n; ++i){
if(home[i].s == work[i].s){
for(int j=0; j<10000; ++j){
ans[j] += abs(home[i].f - work[i].f);
}
continue;
}
for(int j=0; j<5000; ++j){
ans[j] += (abs(home[i].f-(median-j)) + abs(median-j-work[i].f)+1);
ans[j+5000] += (abs(home[i].f-(median+j)) + abs(median+j-work[i].f)+1);
}
}
cout << *min_element(all(ans));
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |