답안 #23485

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
23485 2017-05-10T07:24:01 Z duongthoi1999 Palembang Bridges (APIO15_bridge) C++14
22 / 100
63 ms 4912 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const int mod = (int) 1e9 + 7;
const ll inf = 1LL << 60;
const int maxn = (int) 1e5 + 5;
const ld eps = 1e-9;

int n, k;
vector<ii> a;
vector<int> v;
ll add, res;

int main() {
    //freopen("test.txt", "r", stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> k >> n;
    rep(i, 1, n + 1) {
        char x, y;
        int l, r;
        cin >> x >> l >> y >> r;
        if(l > r) swap(l, r);
        if(x == y) add += r - l;
        else {
            a.pb(ii(l, r));
            v.pb(l);
            v.pb(r);
        }
    }
    if(!v.empty()) {
        sort(all(v));
        int p = v[SZ(v) / 2];
        for (auto i : a) res += 1 + abs(i.fi - p) + abs(i.se - p);
    }
    res += add;
    cout << res << endl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Correct 0 ms 2180 KB Output is correct
4 Correct 0 ms 2180 KB Output is correct
5 Correct 0 ms 2180 KB Output is correct
6 Correct 0 ms 2180 KB Output is correct
7 Correct 0 ms 2180 KB Output is correct
8 Correct 0 ms 2180 KB Output is correct
9 Correct 0 ms 2180 KB Output is correct
10 Correct 0 ms 2180 KB Output is correct
11 Correct 0 ms 2180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Correct 0 ms 2180 KB Output is correct
4 Correct 0 ms 2180 KB Output is correct
5 Correct 0 ms 2180 KB Output is correct
6 Correct 0 ms 2180 KB Output is correct
7 Correct 0 ms 2180 KB Output is correct
8 Correct 0 ms 2180 KB Output is correct
9 Correct 0 ms 2180 KB Output is correct
10 Correct 0 ms 2180 KB Output is correct
11 Correct 0 ms 2180 KB Output is correct
12 Correct 23 ms 4912 KB Output is correct
13 Correct 43 ms 4912 KB Output is correct
14 Correct 33 ms 4912 KB Output is correct
15 Correct 26 ms 3632 KB Output is correct
16 Correct 36 ms 4912 KB Output is correct
17 Correct 36 ms 4912 KB Output is correct
18 Correct 39 ms 4912 KB Output is correct
19 Correct 63 ms 4912 KB Output is correct
20 Correct 26 ms 4912 KB Output is correct
21 Correct 46 ms 4912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Incorrect 0 ms 2180 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Incorrect 0 ms 2180 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Correct 0 ms 2180 KB Output is correct
3 Incorrect 0 ms 2180 KB Output isn't correct
4 Halted 0 ms 0 KB -