# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
660885 | danikoynov | Palembang Bridges (APIO15_bridge) | C++14 | 4 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 1e5 + 10;
struct work
{
ll x, y;
} w[maxn];
int k, n;
void solve()
{
cin >> k >> n;
ll ans = 0;
vector < ll > v;
for (int i = 1; i <= n; i ++)
{
char c1, c2;
cin >> c1 >> w[i].x >> c2 >> w[i].y;
if (w[i].x > w[i].y)
swap(w[i].x, w[i].y);
if (c1 == c2)
{
ans = ans + w[i].y - w[i].x;
i --;
n --;
}
else
{
v.push_back(w[i].y);
v.push_back(w[i].x);
ans ++;
}
}
for (int i = 1; i <= n; i ++)
cout << w[i].x << " - " << w[i].y << endl;
if (k == 1)
{
sort(v.begin(), v.end());
for (int i = 0; i < v.size() / 2; i ++)
ans = ans - (v[i]);
for (int i = v.size() / 2; i < v.size(); i ++)
ans = ans + v[i];
cout << ans << endl;
}
else
{
ll best = 1e18;
if (v.empty())
best = 0;
for (int i = 0; i < v.size(); i ++)
for (int j = i + 1; j < v.size(); j ++)
{
ll cur = 0;
for (int d = 1; d <= n; d ++)
{
cur = cur + min(abs(w[d].x - v[i]) + abs(w[d].y - v[i]),
abs(w[d].x - v[j]) + abs(w[d].y - v[j]));
}
best = min(best, cur);
}
cout << ans + best << endl;
}
}
int main()
{
solve();
return 0;
}
/**
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... |