답안 #682518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
682518 2023-01-16T11:58:43 Z 79brue Palembang Bridges (APIO15_bridge) C++17
0 / 100
1 ms 312 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, k;
ll base, ans;
ll a[100002], b[100002];

int main(){
    scanf("%d %d", &k, &n);
    for(int i=1; i<=n; i++){
        char C1, C2;
        int X1, X2;
        scanf(" %c %d %c %d", &C1, &X1, &C2, &X2);
        if(C1==C2) base += abs(X1-X2), n--, i--;
        else a[i] = X1, b[i] = X2;
    }
    if(k==1){
        vector<ll> vec;
        for(int i=1; i<=n; i++) vec.push_back(a[i]), vec.push_back(b[i]);
        sort(vec.begin(), vec.end());
        ans = 1e18;

        ll lsum = 0, lcnt = 0, rsum = accumulate(vec.begin(), vec.end(), 0LL), rcnt = (int)vec.size();
        for(int i=0; i<n*2; i++){
            rsum -= vec[i], rcnt--;
            ans = min(ans, (lcnt * vec[i] - lsum) + (rsum - rcnt * vec[i]) + n);
            lsum += vec[i], lcnt++;
        }
        printf("%lld", ans+base);
        return 0;
    }


}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %d", &k, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~
bridge.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf(" %c %d %c %d", &C1, &X1, &C2, &X2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -