답안 #1095154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095154 2024-10-01T12:49:20 Z NguyenPhucThang Palembang Bridges (APIO15_bridge) C++14
0 / 100
9 ms 16108 KB
#include <bits/stdc++.h>
#define forr(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(), v.end()
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

using namespace std;
const int base = 31;
const ll mod = 1e9 + 7;
const ll oo = 1e18;
const int N = 1e6 + 5;
const int M = 1e6;

ll s[N], cnt[N];

int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);

    int K, n;
    cin >> K >> n;
    ll res = 0;
    forr(i, 1, n){
        char b1, b2;
        int x1, x2;
        cin >> b1 >> x1 >> b2 >> x2;
        if (b1 == b2){
            res += abs(x1 - x2);
        }
        else {
            res++;
            cnt[x1]++;
            cnt[x2]++;
        }
    }

    forr(i, 1, M) {
        s[i] = s[i - 1] + cnt[i] * i;
        cnt[i] += cnt[i - 1];
    }

    ll cost1 = oo;
    forr(x, 0, M){
        cost1 = min(cost1, x * cnt[x] - s[x] + (s[M] - s[x]) - x * (cnt[M] - cnt[x]));
    }

    cout << res + cost1;

   return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15964 KB Output is correct
2 Correct 8 ms 15964 KB Output is correct
3 Correct 8 ms 15964 KB Output is correct
4 Correct 7 ms 15960 KB Output is correct
5 Runtime error 1 ms 604 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15960 KB Output is correct
2 Correct 9 ms 15964 KB Output is correct
3 Correct 8 ms 16064 KB Output is correct
4 Correct 7 ms 16028 KB Output is correct
5 Runtime error 1 ms 604 KB Execution killed with signal 11
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16056 KB Output is correct
2 Correct 8 ms 15968 KB Output is correct
3 Incorrect 8 ms 15964 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 15964 KB Output is correct
2 Correct 8 ms 15964 KB Output is correct
3 Incorrect 8 ms 16108 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 15964 KB Output is correct
2 Correct 8 ms 15964 KB Output is correct
3 Incorrect 8 ms 15960 KB Output isn't correct
4 Halted 0 ms 0 KB -