답안 #1021787

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1021787 2024-07-13T05:22:11 Z vjudge1 이상적인 도시 (IOI12_city) C++17
55 / 100
119 ms 2164 KB
#include<bits/stdc++.h>
using namespace std;
int mod=1e9;
long long ANS;
bitset<2010>done;
queue<pair<int,int>>q;
vector<int>adj[2010];
map<pair<int,int>,int>S;
void flod(){
    while(q.size()) {
        auto[x,d]=q.front();
        q.pop();
        if(done[x])continue;
        done[x]=1;ANS+=d;
        for(auto i:adj[x])
            q.push({i,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[{X[i]-=B,Y[i]-=A}]=i;
    for(int i=0;i<N;i++){
        if(S.count({X[i]-1,Y[i]}))
            adj[i].push_back(S[{X[i]-1,Y[i]}]);
        if(S.count({X[i]+1,Y[i]}))
            adj[i].push_back(S[{X[i]+1,Y[i]}]);
        if(S.count({X[i],Y[i]-1}))
            adj[i].push_back(S[{X[i],Y[i]-1}]);
        if(S.count({X[i],Y[i]+1}))
            adj[i].push_back(S[{X[i],Y[i]+1}]);
    }
    for(int i=0;i<N;i++){
        q.push({i,0});
        flod();
        done.reset();
    }
    return ANS/2%mod;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 1 ms 488 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 344 KB Output is correct
2 Correct 26 ms 600 KB Output is correct
3 Correct 49 ms 604 KB Output is correct
4 Correct 58 ms 604 KB Output is correct
5 Correct 85 ms 600 KB Output is correct
6 Correct 111 ms 688 KB Output is correct
7 Correct 85 ms 604 KB Output is correct
8 Correct 116 ms 600 KB Output is correct
9 Correct 113 ms 604 KB Output is correct
10 Correct 119 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 600 KB Output is correct
2 Correct 4 ms 616 KB Output is correct
3 Correct 10 ms 1116 KB Output is correct
4 Correct 15 ms 1380 KB Output is correct
5 Correct 18 ms 1884 KB Output is correct
6 Correct 22 ms 1920 KB Output is correct
7 Correct 20 ms 2164 KB Output is correct
8 Correct 18 ms 1884 KB Output is correct
9 Correct 19 ms 1920 KB Output is correct
10 Correct 18 ms 1880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -