Submission #236791

# Submission time Handle Problem Language Result Execution time Memory
236791 2020-06-03T10:11:30 Z LittleFlowers__ Palembang Bridges (APIO15_bridge) C++17
0 / 100
5 ms 384 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0);
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define gg exit(0);

const int N=100010;

int n,k,tot;
ii a[N];

main(){
    #define task "vim"
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);

    k=in;
    forinc(i,1,in){
        char x, xx; while(!isupper(x=getchar())); xx=in;
        char y, yy; while(!isupper(y=getchar())); yy=in;
        if(x==y)
            tot+=abs(xx-yy);
        else
            a[++n]={xx,yy};
    }

    if(k==1){
        vector<int> val;
        forinc(i,1,n){
            val.push_back(a[i].fi);
            val.push_back(a[i].se);
        }
        sort(all(val));
        vector<int> pf(n+n+1);
        forinc(i,1,n+n)
            pf[i]=pf[i-1] + val[i-1];
        int opt=LLONG_MAX;
        forinc(i,1,n+n)
            opt=min(opt,i*val[i-1] - pf[i] + pf[n+n]-pf[i] - (n+n-i)*val[i-1]);
        cout<<opt+tot+n<<"\n";
    }
}

Compilation message

bridge.cpp:28:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -