제출 #98218

#제출 시각아이디문제언어결과실행 시간메모리
98218luciocf이상적인 도시 (IOI12_city)C++14
0 / 100
11 ms908 KiB
#include <bits/stdc++.h> #define x first #define y second using namespace std; const int maxn = 1e5+10; const long long mod = 1e9; typedef long long ll; typedef pair<int, int> pii; int n; ll soma[maxn]; pii pt[maxn]; bool comp(pii a, pii b) {return a.y < b.y;} int DistanceSum(int N, int *X, int *Y) { n = N; for (int i = 0; i < n; i++) pt[i+1] = {X[i], Y[i]}; sort(pt+1, pt+n+1); for (int i = 1; i <= n; i++) soma[i] = (soma[i-1]+(ll)pt[i].x)%mod; ll ans = 0LL; for (int i = 1; i <= n; i++) { ll v = (soma[n]-soma[i]+mod)%mod; ans = (ans+v)%mod; ans = (ans-((n-i)*(ll)pt[i].x)%mod+mod)%mod; v = soma[i-1]; ans = (ans-v+mod)%mod; ans = (ans+((i-1)*(ll)pt[i].x)%mod)%mod; } sort(pt+1, pt+n+1, comp); for (int i = 1; i <= n; i++) soma[i] = (soma[i-1]+(ll)pt[i].y)%mod; for (int i = 1; i <= n; i++) { ll v = (soma[n]-soma[i]+mod)%mod; ans = (ans+v)%mod; ans = (ans-(((ll)n-(ll)i)*(ll)pt[i].y)%mod+mod)%mod; v = soma[i-1]; ans = (ans-v+mod)%mod; ans = (ans+(((ll)i-1LL)*(ll)pt[i].y)%mod)%mod; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...