Submission #110946

#TimeUsernameProblemLanguageResultExecution timeMemory
110946PeppaPigPalembang Bridges (APIO15_bridge)C++14
0 / 100
4 ms384 KiB
#include <bits/stdc++.h>

#define long long long
#define pii pair<int, int>
#define x first
#define y second

using namespace std;

const int N = 1e5+5;

int k, n;
long ans;
vector<pii> v;

int main() {
    scanf("%d %d", &k, &n);
    for(int i = 1; i <= n; i++) {
        char a, c; int b, d;
        scanf(" %c %d %c %d", &a, &b, &c, &d);
        if(b > d)  swap(b, d);
        if(a == c) ans += d - b;
        else v.emplace_back(b, d);
    }
    n = v.size(), ans += n;
    if(!v.empty()) {
        sort(v.begin(), v.end(), [&](const pii &a, const pii &b) {
            return a.x + a.y < b.x + b.y;
        });
        if(k == 1) {
            int bridge = (v[(n - 1) / 2].x + v[(n - 1) / 2].y) / 2;
            for(int i = 0; i < n; i++) {
                ans += abs(bridge - v[i].x);
                ans += abs(bridge - v[i].y);
            }
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &k, &n);
     ~~~~~^~~~~~~~~~~~~~~~~
bridge.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c %d %c %d", &a, &b, &c, &d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...