Submission #413113

# Submission time Handle Problem Language Result Execution time Memory
413113 2021-05-28T09:07:38 Z A_D Ideal city (IOI12_city) C++14
0 / 100
9 ms 1912 KB
#include <bits/stdc++.h>

#define LL long long

using namespace std;

vector<LL> x,y;
vector<LL> prex,prey;
int DistanceSum(int N,int *X,int *Y){
    x.clear();prex.clear();y.clear();prey.clear();

    for(int i=0;i<N;i++){
        x.push_back(X[i]);
        y.push_back(Y[i]);
    }
    sort(x.begin(),x.end());
    sort(y.begin(),y.end());
    prex.push_back(x[0]);
    prey.push_back(y[0]);
    for(int i=1;i<N;i++){
        prex[i]=prex[i-1]+x[i];
        prey[i]=prey[i-1]+y[i];
    }
    LL ans=0;
    for(int i=0;i<N;i++){
         int l=0,r=N-2,ann;
         while(l<=r){
            int mid=(l+r)/2;
            if(x[mid]<=X[i]){
                ann=mid;
                l=mid+1;
            }
            else r=mid-1;
         }
         ans+=X[i]*(ann+1)-prex[ann];
         ans+=prex[N-1]-prex[ann]-(N-1-ann)*X[i];



         l=0,r=N-2;
         while(l<=r){
            int mid=(l+r)/2;
            if(y[mid]<=Y[i]){
                ann=mid;
                l=mid+1;
            }
            else r=mid-1;
         }
         ans+=Y[i]*(ann+1)-prey[ann];
         ans+=prey[N-1]-prey[ann]-(N-1-ann)*Y[i];
    }
    return ans;
}







Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:37:39: warning: 'ann' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |          ans+=prex[N-1]-prex[ann]-(N-1-ann)*X[i];
      |                                   ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 332 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 1912 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 1876 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -