Submission #804180

# Submission time Handle Problem Language Result Execution time Memory
804180 2023-08-03T07:28:25 Z Dan4Life Ideal city (IOI12_city) C++17
55 / 100
91 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 D[2010][2010], M[2010][2010];
queue<pair<int,int>> Q;

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

Compilation message

city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:33:13: warning: unused variable 'j' [-Wunused-variable]
   33 |     for(int j : {0,1}){
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 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 1 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 2 ms 476 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 20 ms 844 KB Output is correct
2 Correct 20 ms 724 KB Output is correct
3 Correct 48 ms 852 KB Output is correct
4 Correct 49 ms 852 KB Output is correct
5 Correct 89 ms 1116 KB Output is correct
6 Correct 73 ms 980 KB Output is correct
7 Correct 91 ms 1436 KB Output is correct
8 Correct 82 ms 1432 KB Output is correct
9 Correct 73 ms 868 KB Output is correct
10 Correct 70 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 11 ms 772 KB Output is correct
4 Correct 10 ms 772 KB Output is correct
5 Correct 21 ms 1168 KB Output is correct
6 Correct 29 ms 1168 KB Output is correct
7 Correct 34 ms 1108 KB Output is correct
8 Correct 21 ms 1160 KB Output is correct
9 Correct 30 ms 1160 KB Output is correct
10 Correct 21 ms 1056 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 -