Submission #804155

# Submission time Handle Problem Language Result Execution time Memory
804155 2023-08-03T07:24:30 Z Dan4Life Ideal city (IOI12_city) C++17
55 / 100
93 ms 1436 KB
#include <bits/stdc++.h>
using namespace std;
using  ll = long long;
const ll MOD = (ll)1e9;
int x[] = {1,-1,0,0};
int y[] = {0,0,1,-1};
int dis[2010][2010], mp[2010][2010];
queue<pair<int,int>> Q;

int DistanceSum(int N, int *X, int *Y) {
    if(N<=2000){
        int D = *min_element(X,X+N), xd = *min_element(Y,Y+N);
        for(int i = 0; i < N; i++) X[i]-=D,Y[i]-=xd;
        ll ans = 0;
        for(int i = 0; i < N; i++) mp[X[i]][Y[i]]=i+1;
        for(int i = 0; i < N; i++){
            Q.push({X[i],Y[i]}); int tot = 0;
            for(int j = 0; j < N; j++) 
                dis[X[j]][Y[j]]=(j!=i)*-1;
            while(!empty(Q)){
                auto [x1,y1] = Q.front(); Q.pop();
                tot+=dis[x1][y1]*(mp[x1][y1]>i); tot%=MOD;
                for(int k = 0; k < 4; k++){
                    int x2 = x1+x[k], y2 = y1+y[k];
                    if(x2<0 or y2<0 or dis[x2][y2]!=-1) continue;
                    dis[x2][y2] = dis[x1][y1]+1, Q.push({x2,y2});
                }
            }
            ans+=tot, ans%=MOD;
        }
        return ans;
    }
    ll ans = 0, tot = 0;
    for(int j : {0,1}){
        tot = 0; sort(X,X+N);
        for(ll i = 0; i < N; i++){
            ans+=(1ll*X[i]*i-tot+MOD)%MOD;
            tot+=X[i], tot%=MOD; ans%=MOD;swap(X[i],Y[i]);
        }
    }
    return (int)ans;
}

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:34:13: warning: unused variable 'j' [-Wunused-variable]
   34 |     for(int j : {0,1}){
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 724 KB Output is correct
2 Correct 21 ms 728 KB Output is correct
3 Correct 49 ms 960 KB Output is correct
4 Correct 47 ms 916 KB Output is correct
5 Correct 88 ms 1112 KB Output is correct
6 Correct 73 ms 980 KB Output is correct
7 Correct 93 ms 1436 KB Output is correct
8 Correct 76 ms 1428 KB Output is correct
9 Correct 83 ms 852 KB Output is correct
10 Correct 71 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 5 ms 520 KB Output is correct
3 Correct 10 ms 724 KB Output is correct
4 Correct 10 ms 724 KB Output is correct
5 Correct 21 ms 1108 KB Output is correct
6 Correct 20 ms 1164 KB Output is correct
7 Correct 22 ms 1108 KB Output is correct
8 Correct 21 ms 1136 KB Output is correct
9 Correct 21 ms 1112 KB Output is correct
10 Correct 21 ms 1164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -