Submission #487983

# Submission time Handle Problem Language Result Execution time Memory
487983 2021-11-17T10:30:09 Z duyanh1704 Palembang Bridges (APIO15_bridge) C++14
22 / 100
41 ms 4072 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int maxN = 1e5;
typedef pair<int, int> ii;
int k, n;
vector<ii> v;

int f(int m){
    int ret = 0;
    for (auto [x, y] : v)
        ret += abs(x - m) + abs(y - m) + 1;
    return ret;
}

int solve(){
    int l = 0, r = (int)1e9;
    while (true){
        if (r - l == 1){
            if (f(l) < f(r)) return f(l);
            return f(r);
        }
        int m = (l + r) >> 1;
        if (f(m) > f(m + 1)) l = m;
        else r = m;
    }
    return -1;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> k >> n;
    int curr = 0;
    for (int i = 1; i <= n; ++i){
        int x, y;
        char p1, p2;
        cin >> p1 >> x >> p2 >> y;
        if (p1 == p2) curr += abs(x - y);
        else{
            v.push_back({x, y});
        }
    }

    int res = solve();
    cout << res + curr;
    return 0;
}

Compilation message

bridge.cpp: In function 'long long int f(long long int)':
bridge.cpp:12:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   12 |     for (auto [x, y] : v)
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 26 ms 2948 KB Output is correct
13 Correct 31 ms 2996 KB Output is correct
14 Correct 22 ms 3016 KB Output is correct
15 Correct 21 ms 1868 KB Output is correct
16 Correct 41 ms 3516 KB Output is correct
17 Correct 33 ms 4072 KB Output is correct
18 Correct 33 ms 3692 KB Output is correct
19 Correct 34 ms 3980 KB Output is correct
20 Correct 30 ms 3628 KB Output is correct
21 Correct 32 ms 3724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Incorrect 0 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -