| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 914953 | 12345678 | Palembang Bridges (APIO15_bridge) | C++17 | 33 ms | 5592 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
#define ll long long
ll k, n, b, d, cnt;
char a, c;
vector<ll> v, l;
vector<pair<ll, ll>> p(nx);
ll res, ans=LLONG_MAX;
ll cal(int b1, int b2)
{
ll tmp=0;
for (int i=0; i<cnt; i++) tmp+=min(abs(p[i].first-b1)+abs(p[i].second-b1), abs(p[i].first-b2)+abs(p[i].second-b2))+1; //cout<<"here "<<p[i].first<<' '<<p[i].second<<' '<<tmp<<'\n';
return tmp;
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>k>>n;
if (k==1)
{
for (int i=0; i<n; i++)
{
cin>>a>>b>>c>>d;
if (a==c)
{
res+=abs(b-d);
continue;
}
v.push_back(b);
v.push_back(d);
res++;
}
sort(v.begin(), v.end());
int md=v[v.size()/2];
for (auto x:v) res+=abs(x-md);
cout<<res;
}
else
{
for (int i=0; i<n; i++)
{
cin>>a>>b>>c>>d;
if (a==c) res+=abs(b-d);
else p[cnt++]={b, d}, l.push_back(b), l.push_back(d);
}
for (int i=0; i<l.size(); i++) for (int j=i+1; j<l.size(); j++) ans=min(ans, res+cal(l[i], l[j])); //cout<<res<<' '<<l[i]<<' '<<l[j]<<' '<<cal(l[i], l[j])<<'\n';
cout<<ans;
}
}
/*
2 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
컴파일 시 표준 에러 (stderr) 메시지
| # | 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... | ||||
