답안 #660885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
660885 2022-11-23T12:54:21 Z danikoynov Palembang Bridges (APIO15_bridge) C++14
0 / 100
4 ms 340 KB
#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
*/

Compilation message

bridge.cpp: In function 'void solve()':
bridge.cpp:53:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         for (int i = 0; i < v.size() / 2; i ++)
      |                         ~~^~~~~~~~~~~~~~
bridge.cpp:55:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |         for (int i = v.size() / 2; i < v.size(); i ++)
      |                                    ~~^~~~~~~~~~
bridge.cpp:66:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |         for (int i = 0; i < v.size(); i ++)
      |                         ~~^~~~~~~~~~
bridge.cpp:67:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |             for (int j = i + 1; j < v.size(); j ++)
      |                                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 4 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 4 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 4 ms 212 KB Output isn't correct
4 Halted 0 ms 0 KB -