Submission #1021778

# Submission time Handle Problem Language Result Execution time Memory
1021778 2024-07-13T05:14:06 Z vjudge1 Ideal city (IOI12_city) C++17
34 / 100
1000 ms 2152 KB
#include<bits/stdc++.h>
using namespace std;
int mod=1e9;
long long ANS;
set<pair<int,int>>S;
queue<array<int,3>>q;
void flod(){
    while(q.size()) {
        auto[x,y,d]=q.front();
        q.pop();
        if(!S.count({x,y}))continue;
        S.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++)
        S.insert({X[i]-=B,Y[i]-=A});
    set<pair<int,int>>st2=S;
    for(int i=0;i<N;i++){
        q.push({X[i],Y[i],0});
        flod();
        S=st2;
    }
    return ANS/2%mod;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 2 ms 344 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 7 ms 348 KB Output is correct
7 Correct 7 ms 348 KB Output is correct
8 Correct 7 ms 348 KB Output is correct
9 Correct 7 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 8 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 263 ms 536 KB Output is correct
2 Correct 241 ms 528 KB Output is correct
3 Correct 601 ms 600 KB Output is correct
4 Correct 574 ms 604 KB Output is correct
5 Execution timed out 1057 ms 604 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 640 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 10 ms 1116 KB Output is correct
4 Correct 9 ms 1112 KB Output is correct
5 Correct 18 ms 1884 KB Output is correct
6 Correct 18 ms 1628 KB Output is correct
7 Correct 20 ms 2152 KB Output is correct
8 Correct 19 ms 1628 KB Output is correct
9 Correct 24 ms 1568 KB Output is correct
10 Correct 19 ms 1804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -