Submission #249664

#TimeUsernameProblemLanguageResultExecution timeMemory
249664rdd6584Palembang Bridges (APIO15_bridge)C++14
0 / 100
1 ms384 KiB
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

vector<pll> v;
ll cal(int mid) {
    ll ret= 0;
    for (pll i : v) {
        if (i.first <= mid && mid <= i.second) continue;
        ret += min(abs(i.first-mid), abs(i.second-mid));
    }
    return ret*2;
}

int main() {
    int k, n;
    scanf("%d %d", &k, &n);

    ll sum = 0;
    for (int i = 0; i < n; i++) {
        char a,c;
        int b,d;
        scanf(" %c %d %c %d", &a, &b ,&c, &d);
        sum += abs(b-d);
        if (a!=c) {
            if (b>d) swap(b,d);
            sum++;
            v.push_back({b, d});
        }
    }

    if (k==1) {
        vector<int> cc;
        for (pll i : v) cc.push_back(i.first), cc.push_back(i.second);
        sort(all(cc));
        printf("%lld", cal(cc[sz(cc)/2])+sum);
        return 0;
    }
    // 이제 k=2인 경우,

}

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:37: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:43: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...