Submission #1021772

# Submission time Handle Problem Language Result Execution time Memory
1021772 2024-07-13T05:10:31 Z vjudge1 Ideal city (IOI12_city) C++17
34 / 100
1000 ms 1292 KB
#include<bits/stdc++.h>
using namespace std;
int mod=1e9;
long long ANS;
set<pair<int,int>>st;
queue<tuple<int,int,int>>q;
void flod(){
    while(q.size()) {
        auto[x,y,d]=q.front();
        q.pop();
        if(!st.count({x,y}))continue;
        st.erase({x,y});ANS+=d;
        q.push({x-1,y,d+1});
        q.push({x+1,y,d+1});
        q.push({x,y-1,d+1});
        q.push({x,y+1,d+1});
    }
}
int DistanceSum(int N, int *X, int *Y) {
    if(N>2000){
        sort(X,X+N);
        sort(Y,Y+N);
        long long ans=0;
        for(long long i=0;i<N;i++){
            ans+=i*X[i] - (N-i-1) *X[i];
            ans%=mod;
        }
        for(long long i=0;i<N;i++){
            ans+=i*Y[i] - (N-i-1) *Y[i];
            ans%=mod;
        }
        return (ans+mod)%mod;
    }
    int A=*min_element(Y,Y+N);
    int B=*min_element(X,X+N);
    for(int i=0;i<N;i++)
        st.insert({X[i]-=B,Y[i]-=A});
    set<pair<int,int>>st2=st;
    for(int i=0;i<N;i++){
        q.push({X[i],Y[i],0});
        flod();
        st=st2;
    }
    return ANS/2%mod;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 7 ms 456 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 7 ms 460 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 8 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 248 ms 524 KB Output is correct
2 Correct 238 ms 344 KB Output is correct
3 Correct 609 ms 576 KB Output is correct
4 Correct 550 ms 604 KB Output is correct
5 Execution timed out 1079 ms 604 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 9 ms 900 KB Output is correct
4 Correct 9 ms 860 KB Output is correct
5 Correct 17 ms 1116 KB Output is correct
6 Correct 18 ms 1116 KB Output is correct
7 Correct 26 ms 1116 KB Output is correct
8 Correct 17 ms 1116 KB Output is correct
9 Correct 19 ms 1116 KB Output is correct
10 Correct 21 ms 1292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -