Submission #43544

# Submission time Handle Problem Language Result Execution time Memory
43544 2018-03-17T14:43:59 Z nonocut Palembang Bridges (APIO15_bridge) C++14
22 / 100
74 ms 2584 KB
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define X first
#define Y second
#define ll long long
const int maxn = 2e5 + 5;
int n,m,k;
pii p[maxn];
int pos[maxn];
ll solve1(int st, int ft) {
    if(st>ft) return 0;
    int sz = 0;
    ll res = 0;
    for(int i=st;i<=ft;i++) pos[sz++] = p[i].X, pos[sz++] = p[i].Y;
    sort(&pos[0],&pos[sz]);
    int opt = pos[sz/2];
    for(int i=0;i<sz;i++) res += abs(opt-pos[i]);
    return res;
}
ll solve2() {
    ll res = 2e16;
    for(int i=1;i<=n;i++) res = min(res, solve1(1,i-1) + solve1(i,n));
    return res;
}
int main() {
    ll extra = 0;
    scanf("%d%d",&k,&n);
    for(int i=1;i<=n;i++) {
        int x, y; char t1, t2;
        scanf(" %c%d %c%d",&t1,&x,&t2,&y);
        if(t1==t2) extra += abs(x-y);
        else {
            p[++m] = {x,y};
            extra++;
        }
    }
    n = m;
    sort(&p[1],&p[n+1]);
    if(k==1) printf("%lld", solve1(1,n) + extra);
    else printf("%lld", solve2() + extra);
}

Compilation message

bridge.cpp: In function 'int main()':
bridge.cpp:28:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&k,&n);
                        ^
bridge.cpp:31:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %c%d %c%d",&t1,&x,&t2,&y);
                                          ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 540 KB Output is correct
5 Correct 2 ms 688 KB Output is correct
6 Correct 2 ms 688 KB Output is correct
7 Correct 2 ms 852 KB Output is correct
8 Correct 2 ms 852 KB Output is correct
9 Correct 2 ms 852 KB Output is correct
10 Correct 3 ms 864 KB Output is correct
11 Correct 2 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 904 KB Output is correct
2 Correct 2 ms 908 KB Output is correct
3 Correct 2 ms 912 KB Output is correct
4 Correct 2 ms 1024 KB Output is correct
5 Correct 2 ms 1024 KB Output is correct
6 Correct 2 ms 1024 KB Output is correct
7 Correct 3 ms 1024 KB Output is correct
8 Correct 2 ms 1024 KB Output is correct
9 Correct 2 ms 1044 KB Output is correct
10 Correct 3 ms 1044 KB Output is correct
11 Correct 2 ms 1044 KB Output is correct
12 Correct 33 ms 2580 KB Output is correct
13 Correct 74 ms 2580 KB Output is correct
14 Correct 56 ms 2580 KB Output is correct
15 Correct 50 ms 2580 KB Output is correct
16 Correct 39 ms 2584 KB Output is correct
17 Correct 50 ms 2584 KB Output is correct
18 Correct 50 ms 2584 KB Output is correct
19 Correct 59 ms 2584 KB Output is correct
20 Correct 44 ms 2584 KB Output is correct
21 Correct 54 ms 2584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2584 KB Output isn't correct
2 Halted 0 ms 0 KB -