Submission #314806

# Submission time Handle Problem Language Result Execution time Memory
314806 2020-10-21T10:50:21 Z talant117408 Ideal city (IOI12_city) C++17
55 / 100
169 ms 34424 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair <ll, ll> pii;
 
#define precision(n) fixed << setprecision(n)
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define eps (double)1e-9
#define PI 2*acos(0.0)
#define endl "\n"
#define sz(v) int((v).size())
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define do_not_disturb ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
int n, moveX[] = {-1, 0, 0, 1}, moveY[] = {0, -1, 1, 0};
ll x[100007], y[100007];
ll ans, dist[2007][2007];
vector <vector <int>> graph(100007);
const int mod = 1e9;
vector <pii> points;
map <ll, pii> row;

void bfs(int p){
    for(int i = 0; i < n; i++){
        dist[p][i] = 9e18;
    }
    dist[p][p] = 0;
    queue <ll> K;
    K.push(p);
    
    while(sz(K)){
        auto u = K.front(); K.pop();
        
        for(auto to : graph[u]){
            if(dist[p][to] == 9e18){
                dist[p][to] = dist[p][u] + 1;
                K.push(to);
            }
        }
    }
}

ll add(ll a, ll b){
    a = ((a%mod)+mod)%mod;
    b = ((b%mod)+mod)%mod;
    return (a+b)%mod;
}

ll mult(ll a, ll b){
    a = ((a%mod)+mod)%mod;
    b = ((b%mod)+mod)%mod;
    return (a*b)%mod;
}

ll calc(ll a){
    return a*(a+1)/2;
}
 
int DistanceSum(int N, int *X, int *Y) {
    int i, j;
    n = N;
    for(i = 0; i < n; i++){
        x[i] = X[i];
        y[i] = Y[i];
        points.pb(mp(x[i], y[i]));
    }
    
    sort(all(points));
    
    for(i = 0; i < n; i++){
        x[i] = points[i].first;
        y[i] = points[i].second;
    }
    
    for(i = 0; i < n; i++){
        ll XX = points[i].first, YY = points[i].second;
        for(j = 0; j < 4; j++){
            ll nx = moveX[j]+XX;
            ll ny = moveY[j]+YY;
            auto it = lb(all(points), mp(nx, ny))-points.begin();
            if(it != sz(points) && points[it] == mp(nx, ny)){
                graph[i].pb(it);
            }
        }
    }
    
    if(n <= 2000){
        for(i = 0; i < n; i++){
            bfs(i);
        }
        for(i = 0; i < n; i++){
            for(j = i+1; j < n; j++){
                ans = add(ans, dist[i][j]);
            }
        }
    }
    else{
        vector <ll> prefx, prefy, Xes, Yes;
        prefx.pb(0); prefy.pb(0);
        Xes.pb(0); Yes.pb(0);
        for(i = 0; i < n; i++){
            Xes.pb(x[i]);
            Yes.pb(y[i]);
            prefx.pb(x[i]);
            prefy.pb(y[i]);
        }
        sort(all(Xes));
        sort(all(Yes));
        sort(all(prefx));
        sort(all(prefy));
        for(i = 1; i <= n; i++){
            prefx[i] += prefx[i-1];
            prefy[i] += prefy[i-1];
        }
        for(i = 1; i <= n; i++){
            ans = add(ans, prefx.back()-prefx[i]-Xes[i]*(n-i));
            ans = add(ans, prefy.back()-prefy[i]-Yes[i]*(n-i));
        }
    }
    
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2816 KB Output is correct
3 Correct 2 ms 2816 KB Output is correct
4 Correct 3 ms 3200 KB Output is correct
5 Correct 3 ms 3200 KB Output is correct
6 Correct 5 ms 3840 KB Output is correct
7 Correct 4 ms 3840 KB Output is correct
8 Correct 4 ms 3840 KB Output is correct
9 Correct 4 ms 3840 KB Output is correct
10 Correct 4 ms 3840 KB Output is correct
11 Correct 4 ms 3840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 14584 KB Output is correct
2 Correct 44 ms 14584 KB Output is correct
3 Correct 99 ms 26372 KB Output is correct
4 Correct 96 ms 26360 KB Output is correct
5 Correct 169 ms 34296 KB Output is correct
6 Correct 157 ms 34424 KB Output is correct
7 Correct 169 ms 34296 KB Output is correct
8 Correct 154 ms 34296 KB Output is correct
9 Correct 167 ms 34364 KB Output is correct
10 Correct 164 ms 34296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 5368 KB Output is correct
2 Correct 21 ms 5496 KB Output is correct
3 Correct 52 ms 9452 KB Output is correct
4 Correct 50 ms 9328 KB Output is correct
5 Correct 102 ms 15980 KB Output is correct
6 Correct 105 ms 15852 KB Output is correct
7 Correct 102 ms 16108 KB Output is correct
8 Correct 102 ms 15948 KB Output is correct
9 Correct 103 ms 15980 KB Output is correct
10 Correct 95 ms 15984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 5368 KB Output isn't correct
2 Halted 0 ms 0 KB -